Skip to content

JDK7 command line changes

September 14, 2013

Java 7 added 2 new commands to $JAVA_HOME/bin:

The first is javafxpackager. Not much to say here: JavaFX never really interested me because I prefer HTML5 to client side technologies like Flash, JavaFX, Silverlight, etc.

jcmd – “Java Command”

jcmd is a utility to send diagnostic command requests to a running Java Virtual Machine. This is another utility that we can thank JRockit for, because it’s based on JRockit’s jrcmd but is now in OpenJDK7 (not sure which update, but definitely 7u25 and later). Below is an example program to receive Java Commands. This program is pretty neat in it’s own right in that it’s concurrent and configurable from command line parameters:

If you run the code above with an example usage (same as in JavaDoc) like:
java RandomizationHistogram 20 21 1
* 20 - threads
* 21 - from 0(inclusive) to 21(exclusive)
* 1 - millisecond delay between thread executions.

Now we can experiment with jcmd on this process. First we have to find the Java Process ID (PID) with either jps or jcmd.
$> jcmd -l
23867 RandomizationHistogram 20 21 1

Then we can ask for what commands we can send this process:

jcmd 23867 help
23867:
The following commands are available:
VM.native_memory
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help

You can also get additional help and options for each of these commands:

jcmd 23867 help Thread.print
23867:
Thread.print
Print all threads with stacktraces.

Impact: Medium: Depends on the number of threads.

Permission: java.lang.management.ManagementPermission(monitor)

Syntax : Thread.print [options]

Options: (options must be specified using the or = syntax)
-l : [optional] print java.util.concurrent locks (BOOLEAN, false)

Advertisements

From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: