JConsole User Manual
An article about JConsole on the Sun project homepage, which was translated for learning some time ago during performance tests. Today, I sorted it out and posted it. I don't know how to translate it in some places, the original Article is retained. It may be easy to understand. Haha, the level is limited, and the translation is not good. I'm sorry.
After all, JConsole is a built-in JDK. Although it is not as powerful as some commercial software, it has good stability and won't cause any problems under heavy pressure. In addition, it is worthwhile to provide a relatively comprehensive system monitoring function.
JConsole
JConsole is a JMX-based GUI tool used to connect to a running JVM. However, this JVM needs to be started in manageable mode. If you want to start an application in a manageable manner, you can setcom.sun.management.jmxremote
. For example, start a J2SE application that can be monitored locally.Java2Demo, Enter the following command:
JDK_HOME/Bin/java-Dcom. sun. management. jmxremote-jarJDK_HOME/Demo/jfc/Java2D/Java2Demo. jarRequired by JDK_HOME
Is a directory containing JDK5.0.
To start JConsole, runJDK_HOME/Bin/jconsole a dialog box for connection will be opened. The Local tab of the dialog box lists all Local running JVMs and contains the process ID and other information.
Figure 2: Local Tab.
JConsole can be connected to a running JVM in three ways:
- Local: Use JConsole to connect to a JVM running on the Local system, and the execution program and JConsole must be the same user. JConsole uses the authorization of the file system to connect to the MBean server of the platform through the RMI connector. Only the JDK of Sun has the monitoring capability of this local connection.
- Remote: Use the following URL to connect to a JMX proxy through the RMI connector:
Service: jmx: rmi: // jndi/rmi ://HostName:PortNum/Jmxrmi
HostNameEnter the Host Name,PortNumThe port specified when the JMX proxy is started. To establish a connection, JConsole must be set in the Environment VariableMx. remote. credentials to specify the user name and password for authorization.
- Advanced: Use a special URL to connect to the JMX proxy. Generally, you can use a custom connector instead of the connector provided by RMI to connect to the JMX proxy, or an application that uses JDK1.4 to implement JMX and JMX Rmote.
When the JConsole successfully establishes a connection, it obtains information from the JMX proxy on the connection and displays information on the following tabs.
- Summary tab. Monitors JVM and some monitoring variable information.
- Memory tab. Memory usage information
- Threads tab. Thread usage information
- Classes tab. Class call Information
- VM tab. JVM Information
- MBeans tab. All MBeans Information
The MBeans tab displays all MBeans registered to the JVM in the general form. The MBeans tab allows you to obtain all platform information, including information that cannot be obtained from other tabs. Note that some information on other tabs is also displayed in MBeans. In addition, you can use MBeans labels to manage MBeans of your own applications.
Use MBeans Tab to monitor and manage MBeans
MBeans registered to the JMX proxy platform or application can be obtained through the MBeans tag. For example, the memory MBeans are defined below
public interface MemoryMXBean { public MemoryUsage getHeapMemoryUsage(); public MemoryUsage getNonHeapMemoryUsage(); public int getObjectPendingFinalizationCount(); public boolean isVerbose(); public void setVerbose(boolean value); public void gc(); }
Memory mbeans have four attributes:
HeapMemoryUsage
. Read-only attribute used to describe the current heap memory usage
NonHeapMemoryUsage
. Read-only attribute used to describe the current usage of non-heap memory
ObjectPendingFinalizationCount
. Used to describe how many objects are suspended for recycling.
Verbose
It is used to dynamically set whether GC follows detailed stack information as a Boolean variable.
Memory MBean supports one operation-GC, which can send real-time garbage collection requests.
Figure 3: MBeans Tab.
The tree structure on the left shows the list of all MBeans by name. The name of an MBean object consists of a domain name and a string of keyword attributes. For example, the MBeans of the JVM platform are in a group under the "java. lang" domain, while the MBeans of logs are in"java.util.logging
"Domain. The MBean object name is defined in the javax. management. ObjectName specification.
When you select an MBean, attribute, method, or notification in the tree, some information will be displayed on the right. If the attribute is writable (the attribute is marked in blue), you can set it. You can operate the Operations listed in the Operations tab. You can also see notifications sent by MBean: by default, if you do not subscribe to notifications, JConsole will not receive notifications from MBean. You can click"Subscribe
"(Subscription) button is used to define heap notifications"Unsubscribe
"Button to cancel subscription
Figure 4: MBeans Notification.
Monitoring memory
The memory tab reads memory systems, memory pools, and garbage collection mbeans to collect statistics on memory consumption, memory pools, and garbage collection.
Figure:
The usage of the Memory changes over time. Statistics on heap, non-heap, and special memory pools are available. Whether the memory pool information can be obtained depends on the Java Virtual Machine Used. The following list shows the memory pool of the HotSpot virtual machine.
Eden Space (heap): the memory is initially allocated to most objects from this thread pool.
Parallel vor Space (heap): an object that is stored in the eden space memory pool and has not been recycled after garbage collection.
Tenured Generation (heap): used to keep objects that have existed in the memory pool of zoovor space for a period of time.
Permanent Generation (non-heap): saves the refective data of the virtual machine, such as class and method objects. Java virtual machines share these types of data. This area is divided into read-only and write-only,
Code Cache (non-heap): the HotSpot Java Virtual Machine includes a memory used to compile and save local code (native code), called "Code cache)
The details area provides information about the current thread:
Used: Current memory usage. The memory used includes the memory occupied by all objects (available and inaccessible.
Committed: Allocation amount: The amount of memory that the Java Virtual Machine can obtain. The amount of memory allocated (committedmemory) may change over time. The Java virtual machine may release some of the memory here to the system. The allocated memory may be less than the amount allocated to it during initialization. The total allocation volume is greater than or equal to the memory used.
Max: the maximum amount of memory that the memory management system can use. This value can be changed or not set. If the JVM tries to increase the memory used to exceed the allocation (committedmemory), the memory allocation may fail, even if the memory used is smaller than or equal to the maximum value (for example: when the system virtual memory is relatively low)
Usage Threshold The usage threshold of a memory pool. This field will only beshown if the memory pool supports usage threshold.
GC time: Total time used for garbage collection and the number of times garbage collection is called. It may have several lines. Each line represents the garbage collection algorithm used by JVM. (
The bar chart in the lower-right corner shows the memory consumed by the JVM memory pool. If the memory usage exceeds usage threshold, the stick will become red. Usagethreshold is an attribute of the Memory Pool MBean that supports Memory checks. MemoryPoolMXBean defines a series of methods for checking memory.
Public interface MemoryPoolMXBean {
....
// Usage threshold
Public long getUsageThreshold ();
Public void setUsageThreshold (long threshold );
Public boolean isUsageThresholdExceeded ();
Public boolean isUsageThresholdSupported ();
// Collection usage threshold
Public long getCollectionUsageThreshold ();
Public void setCollectionUsageThreshold (long threshold );
Public boolean isCollectionUsageThresholdSupported ();
Public boolean isCollectionUsageThresholdExceeded ();
}
Each memory pool may support two types of initial memory: usage threshold and collection usage threshold. Either of them is not supported.
Usage Threshold
Usage thresholdIs a manageable attribute in the memory pool. It uses low-load memory monitoring. SetUsage thresholdIf it is positiveUsage thresholdCheck the memory pool. SetUsage thresholdIf the value is 0, the check is disabled. The default value is set by JVM. JVM generally enables usage threshold to check the memory at the most appropriate time, typically during GC and some memory allocation. If the JVM finds that the current memory usage exceedsUsage threshold,It willUsageThresholdExceeded
Set property to true
Some memory pools may not supportUsage threshold.You can useUsageThresholdSupported attribute to determine whether a memory pool supports
Usage threshold.For example, a well-developed (generational garbage collector) garbage collector (such as a HotSpot Virtual Machine), most of the objects are allocated in the young generation, which is generated from the eden memory pool. The eden pool is designed to be full; garbage collection in the eden pool will release it.
For more details, please continue to read the highlights on the next page: