{"id":211,"date":"2012-04-27T10:53:01","date_gmt":"2012-04-27T09:53:01","guid":{"rendered":"http:\/\/hirt.se\/blog\/?p=211"},"modified":"2012-04-27T20:28:49","modified_gmt":"2012-04-27T19:28:49","slug":"cool-new-features-in-jdk7-update-4","status":"publish","type":"post","link":"https:\/\/hirt.se\/blog\/?p=211","title":{"rendered":"Cool New Features in JDK7 update 4!"},"content":{"rendered":"<p>JDK7 was quite recently released, and I thought I should mention a few new cool things in it. <\/p>\n<h3>JCMD<\/h3>\n<p>First out is the port of the small JRockit command line utility JRCMD (JRockit Command). JRCMD was a command line tool to enumerate the Java processes running on the local machine, and to send commands (referred to as \u201cDiagnostic Commands\u201d) to them. JRCMD has been renamed JCMD (Java Command). <\/p>\n<p>To list the locally running JVMs, simply run JAVA_HOME\\bin\\jcmd:<\/p>\n<blockquote>\n<p><font size=\"3\" face=\"Courier New\">C:\\Java\\JDKs\\JDK7_u4_official\\bin&gt;.\\jcmd       <br \/>4636 sun.tools.jconsole.JConsole        <br \/>2620 HotspotKeepAlive        <br \/>1076 sun.tools.jcmd.JCmd<\/font><\/p>\n<\/blockquote>\n<p>You will see the JVMs running on the local machine listed by PID followed by main class. To see the commands available, run the help command, like this:<\/p>\n<blockquote>\n<p><font size=\"3\" face=\"Courier New\">C:\\Java\\JDKs\\JDK7_u4_official\\bin&gt;.\\jcmd 4636 help       <br \/>4636:        <br \/>The following commands are available:        <br \/>VM.commercial_features        <br \/>ManagementAgent.stop        <br \/>ManagementAgent.start_local        <br \/>ManagementAgent.start        <br \/>Thread.print        <br \/>GC.class_histogram        <br \/>GC.heap_dump        <br \/>GC.run_finalization        <br \/>GC.run        <br \/>VM.uptime        <br \/>VM.flags        <br \/>VM.system_properties        <br \/>VM.command_line        <br \/>VM.version        <br \/>help<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">For more information about a specific command use &#8216;help &lt;command&gt;&#8217;.<\/font><\/p>\n<\/blockquote>\n<p>To get information about a specific command, use the help command followed by the command name:<\/p>\n<blockquote>\n<p><font size=\"3\" face=\"Courier New\">C:\\Java\\JDKs\\JDK7_u4_official\\bin&gt;.\\jcmd 4636 help Thread.print       <br \/>4636:        <br \/>Thread.print        <br \/>Print all threads with stacktraces.<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">Impact: Medium: Depends on the number of threads.<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">Syntax : Thread.print [options]<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">Options: (options must be specified using the &lt;key&gt; or &lt;key&gt;=&lt;value&gt; syntax)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; -l : [optional] print java.util.concurrent locks (BOOLEAN, false)        <br \/><\/font><\/p>\n<\/blockquote>\n<p>To get a thread stack dump with the concurrent locks:<\/p>\n<blockquote>\n<p><font size=\"3\" face=\"Courier New\">C:\\Java\\JDKs\\JDK7_u4_official\\bin&gt;.\\jcmd 4636 Thread.print -l       <br \/>4636:        <br \/>2012-04-27 11:21:57        <br \/>Full thread dump Java HotSpot(TM) Client VM (23.0-b21 mixed mode, sharing):<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&quot;DestroyJavaVM&quot; prio=6 tid=0x003fb000 nid=0xc5c waiting on condition [0x00000000       <br \/>]        <br \/>&#160;&#160; java.lang.Thread.State: RUNNABLE<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&#160;&#160; Locked ownable synchronizers:       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; None<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&quot;AWT-EventQueue-0&quot; prio=6 tid=0x03e65800 nid=0x128c waiting on condition [0x041c       <br \/>f000]        <br \/>&#160;&#160; java.lang.Thread.State: WAITING (parking)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.misc.Unsafe.park(Native Method)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; parking to wait for&#160; &lt;0x2926dce8&gt; (a java.util.concurrent.locks.Abstra        <br \/>ctQueuedSynchronizer$ConditionObject)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject        <br \/>.await(AbstractQueuedSynchronizer.java:2043)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventQueue.getNextEvent(EventQueue.java:511)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre        <br \/>ad.java:213)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.        <br \/>java:163)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre        <br \/>ad.java:151)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&#160;&#160; Locked ownable synchronizers:       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; None<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&quot;Thread-2&quot; prio=6 tid=0x03e61c00 nid=0xd4c in Object.wait() [0x042bf000]       <br \/>&#160;&#160; java.lang.Thread.State: TIMED_WAITING (on object monitor)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.lang.Object.wait(Native Method)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; waiting on &lt;0x292432b0&gt; (a java.io.PipedInputStream)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.io.PipedInputStream.read(PipedInputStream.java:327)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; locked &lt;0x292432b0&gt; (a java.io.PipedInputStream)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.io.PipedInputStream.read(PipedInputStream.java:378)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; locked &lt;0x292432b0&gt; (a java.io.PipedInputStream)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; locked &lt;0x29249358&gt; (a java.io.InputStreamReader)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.io.InputStreamReader.read(InputStreamReader.java:184)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.io.BufferedReader.fill(BufferedReader.java:154)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.io.BufferedReader.readLine(BufferedReader.java:317)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; locked &lt;0x29249358&gt; (a java.io.InputStreamReader)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at java.io.BufferedReader.readLine(BufferedReader.java:382)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; at sun.tools.jconsole.OutputViewer$PipeListener.run(OutputViewer.java:10        <br \/>9)<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">&#160;&#160; Locked ownable synchronizers:       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8211; None<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">.<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">.<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">.       <br \/>JNI global references: 528<\/font><\/p>\n<\/blockquote>\n<h3>Java Flight Recorder<\/h3>\n<p>The second big feature is the first port of the JRockit Flight Recorder \u2013 a high performance event recorder built into the JVM. Think of it as the data flight recorder (black box) of an aircraft. It records information about the JVM, its environment and the application running in the JVM, so that, if something happens, clues about what caused the problem can be found. Now, the first port of the flight recorder is quite limited in terms of the events actually being recorded. It is really released to be used with the event producer built into WebLogic Server through WLDF. Also, the Mission Control client is not yet released as part of the JDK (since it is not that useful without WLDF yet). If you\u2019re an Oracle WebLogic customer, you can download the client on MOS. <\/p>\n<p>That being said, to enable the functionality in 7u4, you need to add the following command line flags to your JVM startup command:<\/p>\n<blockquote>\n<p><font size=\"3\" face=\"Courier New\">JAVA_HOME\\bin\\java -XX:+UnlockCommercialFeatures -XX:+FlightRecorder &lt;your main class and params&gt;<\/font><\/p>\n<\/blockquote>\n<p>You can see that it has been enabled by using JCMD. A few flight recorder specific commands should now be available:<\/p>\n<blockquote>\n<p><font size=\"3\" face=\"Courier New\">C:\\Java\\JDKs\\JDK7_u4_official\\bin&gt;.\\jcmd 2620 help       <br \/>2620:        <br \/>The following commands are available:        <br \/>JFR.stop        <br \/>JFR.start        <br \/>JFR.dump        <br \/>JFR.check        <br \/>VM.commercial_features        <br \/>ManagementAgent.stop        <br \/>ManagementAgent.start_local        <br \/>ManagementAgent.start        <br \/>Thread.print        <br \/>GC.class_histogram        <br \/>GC.heap_dump        <br \/>GC.run_finalization        <br \/>GC.run        <br \/>VM.uptime        <br \/>VM.flags        <br \/>VM.system_properties        <br \/>VM.command_line        <br \/>VM.version        <br \/>help<\/font><\/p>\n<p><font size=\"3\" face=\"Courier New\">For more information about a specific command use &#8216;help &lt;command&gt;&#8217;.<\/font><\/p>\n<\/blockquote>\n<p>Unless you are a WLS user, I\u2019d personally recommend waiting a release or two before starting using the Flight Recorder. There are not that many OS\/JVM\/JDK level events available yet, and there is a major performance improvement related to the time stamping of events just around the corner. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>JDK7 was quite recently released, and I thought I should mention a few new cool things in it. JCMD First out is the port of the small JRockit command line utility JRCMD (JRockit Command). JRCMD was a command line tool to enumerate the Java processes running on the local machine, and to send commands (referred [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-java-mission-control-fair-dj"],"_links":{"self":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":5,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":216,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions\/216"}],"wp:attachment":[{"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hirt.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}