Java Reference
In-Depth Information
Some Java language features may have surprising implementa‐
tions in bytecode. For example, as we saw in
Chapter 9
, Java's
String
class has effectively immutable instances and the JVM
implements the string concatenation operator
+
by instantiat‐
ing a new
StringBuilder
object from the orginal string,
mutating it and finally calling
toString()
on the resulting
(new) instance. This is clearly visible in the disassembled byte‐
code shown by
javap
.
VisualVM
JVisualVM (often referred to as VisualVM) is a graphical tool, based on the Net‐
beans platform. It is used for monitoring JVMs and essentially acts as an equivalent,
graphical aggregate of many of the tools featured in
“Command-Line Tools” on page
349
.
jvisualvm
is a replacement for the
jconsole
tool common in
earlier Java versions. The compatability plug-in available for
visualvm
obsoletes
jconsole
; all installations using
jconsole
should migrate.
VisualVM was introduced with Java 6, and is contained in the Java distribution
package. However, generally, the standalone version of VisualVM is more up to date
and a better choice for serious work. You can download the latest version from
After downloading, ensure that the visualvm binary is added to your PATH or you'll
get the JRE default binary.
The first time you run VisualVM, it will calibrate your machine, so make sure that
you aren't running any other applications while calibration is being performed.
After calibration, VisualVM will open to a screen like that shown in
Figure 13.1
.
To attach VisualVM to a running process, there are slightly different approaches
depending on whether the process is local or remote.
Local processes are listed down the left-hand side of the screen. Double-click on one
of the local processes and it will appear as a new tab on the right-hand pane.
For a remote process, enter the hostname and a display name that will be used on
the tab. The default port to connect to is 1099, but this can be changed.
In order to connect to a remote process,
jstatd
must be running on the remote
host (see the entry for
jstatd
in
“Command-Line Tools” on page 349
for more
details). If you are connecting to an application server, you may find that the app
server vendor provides an equivalent capability to
jstatd
directly in the server, and
that
jstatd
is unnecessary.