Troubleshooting Java Applications

Source: Internet
Author: User

For online users, often due to high traffic, program bugs, dependency failures, thread deadlock, configuration errors and other causes the system does not need to introduce some common Java troubleshooting tools to troubleshoot problems.


First, common tools:

The JDK itself provides a series of Java troubleshooting tools, albeit simple, but useful.

1,jps

JPS is used to output some JVM virtual machine process information, similar to the Linux PS command, its role is to display the current system of Java process, and its ID number. We can use it to see how many Java processes we've started ( because each Java program will have a single Java virtual machine instance ), and their process number (to prepare for the next few programs). You can also view the detailed startup parameters for these processes through opt.

Usage of JPS:

-Q: Only PID is displayed, the class name is not displayed, the jar file name and the parameters passed to the main method

-m: arguments passed to the main function when the output process starts

-L: The full package name of the main class of the output application or the full pathname of the application's jar file

-V: Output parameters passed to the JVM

[Email protected] ~]# jps-v

30319 Bootstrap-djava.util.logging.config.file=/usr/local/webserver/apache-tomcat-cms

Note: The JPS command appears to show only the current user's Java process, whether to show other users or only unix/linux PS commands


2, Jstat

Jstat is a tool that can be used to monitor the running state of a virtual machine's stations, through which it can see the class loading of virtual machines, with unloading, managing memory usage and garbage collection information, and monitoring JIT-timely compiler operation. General is the first choice of the operation period positioning problem

Usage of Jstat:

Jstat-class PID: Displays the number of loaded classes, and the amount of space that is occupied.

Jstat-compiler PID: Displays information such as the number of real-time VMS compiled.

JSTAT-GC PID: can display GC information, view GC number of times, and time. The last five items were the number of young GC, the time of young GC, the number of full GC, the time of full GC, and the total time of GC.

Jstat-gccapacity: It can be shown that the use and occupancy of three generation (Young,old,perm) objects in VM memory, such as: PGCMN shows the minimum perm memory usage, PGCMX shows the maximum amount of memory used for Perm, The PGC is the current newly generated perm memory footprint, and the PC is but the pre-perm memory footprint. The other can be based on this analogy, OC is the old inside the pure consumption.

Jstat-gcnew the information for the Pid:new object.

Jstat-gcnewcapacity the information of the Pid:new object and its consumption.

Jstat-gcold the information for the Pid:old object.

Jstat-gcoldcapacity the information of the Pid:old object and its consumption.

Jstat-gcpermcapacity the information of the Pid:perm object and its consumption.

Jstat-util PID: Statistical GC information statistics.

Jstat-printcompilation PID: Information for the current VM execution.

In addition to one of the above parameters, you can also add two numbers at the same time, such as: Jstat-printcompilation 3024 250 6 is printed every 250 milliseconds, a total of 6 times, you can add-h3 every three lines to display the title.


[Email protected] ~]# jstat-class 32388 (PID)

Loaded Bytes Unloaded Bytes time

9012 18808.3 191) 301.6 54.46


3.jinfo

Used to view configuration parameters for an application and to print the JVM parameters specified when running the JVM.

Observe the running environment parameters for Java programs in operation: Parameters include Java System Properties and JVM command-line arguments
Example: Jinfo 2083
Where 2083 is the Java process ID number, you can use JPS to get this ID number.

[[email protected] ~]# Jinfo (-flags) 30823 (ID)

Attaching to process ID 30823, please wait ...

Debugger attached successfully.

Server compiler detected.

JVM version is 23.1-b03


Jstack:

You can observe the current status of all threads in the JVM and the current state of the thread

to produce the current thread snapshot information for a virtual machine , thread snapshot information is a collection of method stacks that each thread is executing in the current virtual machine, and the purpose of the production line snapshot is primarily to locate the reason that the thread has not responded for a long time, such as thread deadlock, network request.

Ms/temp

[Email protected] ~]# Jstack 30823

2014-11-14 17:52:57

Full thread dump Java HotSpot (TM) 64-bit Server VM (23.1-b03 mixed mode):


"Attach Listener" daemon prio=10 tid=0x00007f91e0001800 nid=0x77e waiting on condition [0x0000000000000000]

Java.lang.Thread.State:RUNNABLE


"Multithreadedhttpconnectionmanager cleanup" daemon prio=10 tid=0x00007f919814f000 nid=0x7907 in object.wait () [ 0X00007F9210E4F000]

Java.lang.Thread.State:WAITING (on object monitor)

At java.lang.Object.wait (Native Method)

At Java.lang.ref.ReferenceQueue.remove (referencequeue.java:135)

-Locked <0x00000007037c9800> (a java.lang.ref.referencequeue$lock)

At Java.lang.ref.ReferenceQueue.remove (referencequeue.java:151)

At Org.apache.commons.httpclient.multithreadedhttpconnectionmanager$referencequeuethread.run ( multithreadedhttpconnectionmanager.java:1122)

.

. Jmap:

You can view the queues that are waiting to be recycled, view the summary of the heap, and specify the amount of memory through the JVM parameters, dump snapshots through JVM heap snapshots, and find memory leaks.

-heap: Print JVM heap Condition
-histo:prints the histogram of the JVM heap. Its output information includes the class name, the number of objects, and the size of the object.
-histo:live:ditto, but only to the survival of the object
-permstat:Print permanent generation heap condition


[Email protected] ~]# jmap-heap 30823

Attaching to process ID 30823, please wait ...

Debugger attached successfully.

Server compiler detected.

JVM version is 23.1-b03


Using Thread-local object allocation.

Parallel GC with 4 thread (s)


Heap Configuration:

Minheapfreeratio = 40

Maxheapfreeratio = 70

Maxheapsize = 4294967296 (4096.0MB)

NewSize = 1310720 (1.25MB)

Maxnewsize = 17592186044415 MB

Oldsize = 5439488 (5.1875MB)

Newratio = 2

Survivorratio = 8

PermSize = 536870912 (512.0MB)

MaxPermSize = 536870912 (512.0MB)

g1heapregionsize = 0 (0.0MB)

Heap Usage:

PS Young Generation

Eden Space:

Capacity = 1267531776 (1208.8125MB)

used = 623225224 (594.353889465332MB)

Free = 644306552 (614.458610534668MB)

49.16841027581466% used

From Space:

Capacity = 83034112 (79.1875MB)

used = 38528120 (36.74327850341797MB)

Free = 44505992 (42.44422149658203MB)

46.40035170123816% used

To Space:

Capacity = 81068032 (77.3125MB)

Used = 0 (0.0MB)

Free = 81068032 (77.3125MB)

0.0% used

PS Old Generation

Capacity = 2863333376 (2730.6875MB)

used = 166141280 (158.44467163085938MB)

Free = 2697192096 (2572.2428283691406MB)

5.802372905389554% used

PS Perm Generation

Capacity = 536870912 (512.0MB)

used = 77216208 (73.63911437988281MB)

Free = 459654704 (438.3608856201172MB)

14.382639527320862% used


39090 interned Strings occupying 4328232 bytes.


BTrace:

A Java dynamic tracking tool for open source, which works by dynamically replacing tracked code within a Java program with tracking based on the HotSwap technology of the hotspot virtual machine

Single, is to be able to not change the current program, the runtime to monitor the execution of the Java program, such as the ability to monitor the memory status, method call monitoring and so on.

Usage:

Btrace

PID: the Java process ID that needs to be traced

-cp--classpath is used to compile the specified desired path, generally referred to as Btrace-client.jar

-p:port, specifying the Btrace agent port

.




This article is from the "Crazy_sir" blog, make sure to keep this source http://douya.blog.51cto.com/6173221/1576605

Troubleshooting Java Applications

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.