How to Use JDK's built-in jvisualvm to monitor Java programs [Java hotspot (TM )]

Source: Internet
Author: User

This article only applies to hostspot virtual machines

Step 1: Write a test policy file named test. Policy and specify that you can access tools. Jar. The content is as follows:

Grant codebase "file: $ {java. Home}/../lib/tools. Jar "{
Permission java. Security. allpermission;
};


Step 2: compile a test program testjvisualvm. Java:

Import Java. util. hashmap; import Java. util. map;/***** test the jvisualvm monitoring function **/public class testjvisualvm {public static void main (string [] ARGs) throws interruptedexception {// simulate the resource-consuming part for (INT I = 0; I <100; I ++) {Map <string, string> map = new hashmap <string, string> (); map. put ("" + I, "" + I); thread t = new thread () {public void run () {try {thread. sleep (200*1000);} catch (interruptedexception e) {e. printstacktrace () ;}}; T. start (); // sleep 1sthread. sleep (1000 );}}}

Step 3: compile:

Javac-encoding utf8 testjvisualvm. Java


Step 4: run:

Java-djava. Security. Policy = test. Policy -djava.net. preferipv4stack = true
-DCOM. Sun. Management. jmxremote. Port = 10990-DCOM. Sun. Management. jmxremote. SSL = false-DCOM. Sun. Management. jmxremote. Authenticate = false testjvisualvm

Step 5: Configure jvisualvm

Add the remote host and then the remote JMX port. The port must be the same as the one specified in-DCOM. Sun. Management. jmxremote. Port = 10990 in the startup file.

Click OK and double-click it. If it is displayed, the configuration is normal:

If an error occurs:

Check the port. If 0: 10990 is displayed

Check parameter: -djava.net. preferipv4stack = true

[Ssergsw @ JAZX5FVM-121-119 Dubbo-antifraud] $ netstat-an | grep 10990
TCP 0 0: 10990: * listen
If you see the following listener, you should be able to access it normally:

[Ssergsw @ JAZX5FVM-121-119 Dubbo-antifraud] $ netstat-an | grep 10990
TCP 0 0 0.0.0.0: 10990 0.0.0.0: * listen

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.