Java JDK Command-line tool detailed

Source: Internet
Author: User
Tags stack trace

Because Java JDK command-line tools are important, and you see a good summary, the next step is explained in detail.

Many Java developers once found that the app was unresponsive, looked at the logs first, and then restarted the Java app without having to find the logs in the first place to let it work again. It is also more exaggerated to hear the production of timed scripts to restart every night, and smile to say that the restart to solve all problems.

This solution is clearly a poor and inexperienced performance. In addition to viewing the date to the Java process JVM, Sun provides a powerful set of virtual machine monitoring and troubleshooting tools. If you have a little knowledge of the JDK, the diagnosis of a Java process is actually the case, we should find the root cause of the problem, from this to find the reason Ava process does not work properly, so as to achieve a root cause.

0. Simply describe what the JDK command-line tool is

We do Java certainly know that the JDK Bin directory has java.exe, javac.exe these two command-line tools. But in addition to these two tools there are some other very useful tools, this article is mainly about the monitoring of virtual machines and troubleshooting tools.

JPS---Virtual machine process health tool

Common parameters:

-L OUTPUT The full package of the main class of the Java application

-Q shows only PID and does not show any other related information

-m output parameters passed to the main method

-V outputs the parameters passed to the JVM. When diagnosing JVM-related problems, this parameter can be used to view the settings of JVM-related parameters

Note: This command believes that most Java programmers are aware of the current running Java process and can be used when a process needs to be killed.

jstat---Virtual machine statistics monitoring Tool

Jstat [generaloption | outputoptions vmid [INTERVAL[S|MS] [count]], can be used to view heap information, garbage collection information, etc., detailed use of commands can be viewed through the man jstat command.

View garbage Collection Information

S0C: Capacity of the first Survivor (Survivor area) in the Young Generation (bytes)

S1C: Capacity of the second survivor (Survivor area) in the younger generation (bytes)

S0U: The first survivor (Survivor area) of the young generation has currently used space (bytes)

S1U: The second survivor (Survivor area) of the young generation has currently used space (bytes)

EC: The Capacity of Eden (Eden) in the Young Generation (bytes)

EU: Eden (Eden) in the young generation has currently used space (bytes)

Capacity of the Oc:old generation (bytes)

Ou:old currently used space (bytes)

Pc:perm (persistent generation) capacity (bytes)

Pu:perm (persistent generation) currently used space (bytes)

YGC: Number of GC times in young generations from application startup to sampling

YGCT: The time taken by the GC in the young generation from application startup to sampling (s)

FGC: Old (full GC) GC count from application boot to sampling

FGCT: Time taken from an old (full GC) GC when the application boots to sampling (s)

GCT: GC Total time from Application boot to sample (s)

NGCMN: initial (minimum) size in Young generation (bytes)

NGCMX: Max capacity of young generation (bytes)

NGC: Current capacity in young generation (bytes)

The size (in bytes) of the initialization (minimum) in ogcmn:old generation

Maximum capacity of the Ogcmx:old generation (bytes)

The current newly generated capacity of the Ogc:old generation (bytes)

The size (in bytes) of the initialization (minimum) in pgcmn:perm generation

Maximum capacity of the Pgcmx:perm generation (bytes)

The current newly generated capacity of the Pgc:perm generation (bytes)

S0: The first survivor (Survivor area) of the young generation has been used as a percentage of current capacity

S1: The second survivor (Survivor area) in the younger generation has been used as a percentage of current capacity

E: Eden (Eden) in the young generation has been used as a percentage of current capacity

Percentage of current capacity used by O:old generation

Percentage of current capacity used by P:perm generation

S0CMX: Maximum Capacity (bytes) of the first Survivor (Survivor area) in the young generation

S1CMX: Maximum capacity of the second survivor (Survivor area) in the younger generation (bytes)

ECMX: Maximum capacity of Eden (Eden) in the Young Generation (bytes)

DSS: Capacity (bytes) currently required for Survivor (surviving area) (Eden area Full)

TT: Limited number of holds

MTT: Maximum number of hold limit

Jinfo Java Configuration Information tool

Observe the running environment parameters for the running Java program: parameters include the Java system property and the JVM command-line arguments, you can also set the value of the parameter and make it effective immediately.

eg

jmap Java Memory Imaging tool

You can generate heap snapshots and object statistics for Java applications.

The following command can see the number of class samples and the number of bytes in the Java process at some point in time.

The print process's class loader and ClassLoader load the persisted object information, Output: Class loader name, whether the object is alive (unreliable), object address, parent ClassLoader, loaded class size, and so on.

1. Use the Jmap-heap PID to view the process heap memory usage, including the GC algorithm used, heap configuration parameters, and heap memory usage in each generation.

2. Use jmap-histo[:live] PID to view the number of objects in the heap memory, size statistics histogram, if you bring live, only live objects are counted.

You can also export a heap snapshot of the current program to a file:

jstack Command (Java Stack Trace)Can be used to view stack information for Java applications.

Jstack-l <pid>

Can be used to view the thread status of the process, detect deadlocks and so on.

Jstack can navigate to the thread stack, which can be targeted to specific code based on stack information, so it is used very much in JVM performance tuning. Let's take a look at the most CPU-consuming Java threads in a Java process and locate the stack information, with the commands PS, top, printf, Jstack, grep.

1.: First find out the Java process ID, the Java application name I deployed on the server is mrf-center:

Get the process ID of 21711

2.: Find the CPU-intensive thread top-hp pid in this process

The time column is the CPU for each Java thread, and the longest CPU time is a thread with a thread ID of 21742

printf "%x" 21742 to get 21742 hexadecimal value of 54ee, the following will be used.

3.:jstack, which is used to output the stack information for process 21711, and then grep based on the thread ID's hexadecimal value, as follows:


PS: Can see CPU consumption in Pollintervalretryschedulerthread this class of object.wait (), I looked under my code, navigate to the following code:

Java JDK Command-line tool detailed

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.