Java-Performance Optimization-tools-jvisualvm

Source: Internet
Author: User

Save it first. Try to use it when necessary.

Java performance optimization is a common problem. This problem is not only encountered during interviews, but also in actual work. We will not discuss the specific details here, this section only describes the Java tool used to check the program's performance problems. Here, I use jvisualvm as an example.

   Visualvm
Is a profile sub-project of netbeans, which is self-contained in jdk6.0 update 7 (no specific parameters are required when Java is started, and the monitoring tool is in Bin/jvisualvm.exe). It can monitor threads and memory conditions, view the CPU time and memory objects of the method, GC objects, and reverse view the allocated stack (for example, which objects are allocated with 100 string objects ), I will not talk about the details here, but it is available in Baidu encyclopedia. I will only introduce how to use this tool.
   Since my server is Linux and does not have a graphic interface, running jvisualvm directly on the server cannot bring up the interface. Therefore, I will run c: \ jvisualvm.exe locally and connect to the server through a remote connection. There are many steps on the Internet. Here I will give you some notes:

  1. During remote connection, pay attention to what servers are running online (I use jetty as an example here, many of them are Tomcat on the Internet), and then open the jetty remote service, as shown below:
    • Under the jetty etc directory, find the jetty-jmx.xml file, then modify the port in the file, replace all the default 1099 ports with unused ports, such as 39527, save and exit
    • In the jetty bin directory, locate the jetty. Sh file and add the startup parameters ,:
  2. After connecting to JMX remotely, focus on two tabs
  • Monitoring,

    When a problem occurs, you can use these linear graphs to preliminarily determine

  • Thread: This is the most important part of the thread. I will not talk about this part here. I mainly pay attention to the following points: when the user thread and jetty server are running, the created thread name starts with qtp

    Other servers have different names when creating threads. Therefore, we only need to find the relevant thread. This thread is in the waiting state, very empty, and has no pressure. If it is always green, it indicates that, this thread is very busy, and the CPU will be very high. Check the relevant details to confirm whether there is a problem. Here we will show which class is running, which can be easily located.

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.