Java Runtime problem Diagnostics-Tools Application

Source: Internet
Author: User

The blog content is in the Department of the Organization to discuss the operation of the issue when the PPT content, content vitalize, mainly for the convenience of reviewing their own later.

Outline includes: 1, run-time problem Classification 2, server comes with tool 3, other tools 4, example 5, actual situation

Runtime problem classification-Software angle: 1, memory leak, Object not released 2, thread blocking, deadlock 3, Thread dead loop 4, network IO Connection timeout time is too long 5, disk is not writable .....

Runtime problem Classification-Hardware angle: 1, high memory consumption 2, high CPU consumption 3, network unresponsive 4, hard disk space full ....

Linux instructions: 1, top, top-hp PID 2, free 3, DF 4, netstat, NETSTAT-NATP ...

JDK instructions: 1, JPS, Jps-v 2, Jstack, Jstack pid 3, Jmap, jmap-dump:format=b,file=/opt/... 4, Jstat, Jstat-gcutil (gc,gccapacity) pid ....

Tools:

Real-time analysis tools: 1, Jconsole 2, VisualVM 3, Jprofiler 4, javamelody 5, Lambdaprobe ....

Offline analysis tools: 1, Memoryanalyzer tool 2, Thread Dump Analyzer ....

Demo:1, Memory overflow 2, CPU high 3, thread deadlock 4, thread blocking

Ready to work: stack memory settings lower, print GC logs and oom output dump file: Set java_opts=-server-xms24m-xmx50m-xx:permsize=28m-xx:maxpermsize=80m-xx:+ Printgcdetails-xx:+heapdumponoutofmemoryerror-xx:heapdumppath=d:\temp\dump

Memory overflow:

map<string, person> map =NewHashmap<string, person>(); Object[] Array=Newobject[1000000];  for(inti =0; I <1000000; i++) {String d=NewDate (). toString (); Person P=NewPerson (d, I); Map.put (i+" Person", p); Array[i]=p; }

mat-Keywords (personal understanding, not necessarily accurate):

Histogram: number and size of objects in an in-memory class object instance

Dominator Tree: Heap Object trees, object size and occupancy percentage

Leak Suspects:mat analysis of the suspect points of memory leaks

Shallow heap: The object itself occupies memory size

Retained heap: Object itself and referenced objects consume memory size

Merge shortest Paths to GC Roots: from the GC root node to the path view of the object

With outgoing references: external object reference held by object

With incomming references: Which external objects are referenced by the object

....

High CPU consumption:

int i = 0;while (i < 1000000) {i++; System.out.println (i); try {thread.sleep (0);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();}}

  

Thread Deadlock:

thread T1 = new Thread (new Syncthread (Obj1, Obj2), "T1"); Thread t2 = new Thread (new Syncthread (Obj2, obj1), "T2"), T1.start (), try {thread.sleep (+);} catch ( Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} T2.start (); synchronized (obj1) {System.out.println ("Main thread lock on" + Obj1.getname ());}

  

Private person Obj1;private person obj2;public syncthread (person O1, person O2) {this.obj1 = O1;this.obj2 = O2;} public void Run () {String name = Thread.CurrentThread (). GetName (); SYSTEM.OUT.PRINTLN (name + "acquiring lock on" + Obj1.getname ()) synchronized (obj1) {System.out.println (name + "acquire") D lock on "+ Obj1.getname ()); work (); SYSTEM.OUT.PRINTLN (name + "acquiring lock on" + Obj2.getname ()) synchronized (OBJ2) {System.out.println (name + "acquire") D lock on "+ Obj2.getname ()); work ();} SYSTEM.OUT.PRINTLN (name + "released lock on" + Obj2.getname ());} SYSTEM.OUT.PRINTLN (name + "released lock on" + Obj1.getname ()); SYSTEM.OUT.PRINTLN (name + "finished execution.");} private void work () {try {thread.sleep (10000);} catch (Interruptedexception e) {e.printstacktrace ()}}

  

Thread Blocking:

Waitthread thread1 = new Waitthread (); Thread1.setname ("Thread 1"); Notifythread thread2 = new Notifythread () thread2.setname ("Thread 2"); Thread1.start (); try {thread.sleep (20000);} catch ( Interruptedexception e) {e.printstacktrace ();} Thread2.start ();

  

public class Notifythread extends Thread {@Overridepublic void run () {synchronized (requestthreadwait.object) { SYSTEM.OUT.PRINTLN ("Thread" + thread.currentthread (). GetName () + "lock occupied"), try {thread.sleep (20000);} catch ( Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} RequestThreadWait.object.notify (); SYSTEM.OUT.PRINTLN ("Thread" + thread.currentthread (). GetName () + "called Object.notify ()"); try {thread.sleep (20000);} catch ( Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();}} SYSTEM.OUT.PRINTLN ("Thread" + thread.currentthread (). GetName () + "release lock");}} public class Waitthread extends Thread {public void run () {synchronized (requestthreadwait.object) {System.out.println (" Thread "+ thread.currentthread (). GetName () +" Get to lock Start "), try {RequestThreadWait.object.wait ();} catch ( Interruptedexception e) {}system.out.println ("thread" + thread.currentthread (). GetName () + "Get to the end of the lock! ");}}}

  

Thread State (personal understanding, not necessarily accurate):

Waiting (parking): thread itself hangs wait, normal

Waiting (on object monitor): Thread actively executes wait, waits for resources, if it is its own program, need to pay attention

BLOCKED (on object monitor): Thread blocking, waiting for the other party to release resources, deadlock occurs if a thread waits for each other to block

Timed_waiting (on Object monitor): The thread called Wait (long timeout), waiting at a specific time

Timed_waiting (sleeping): Called Sleeping, sleeps for a period of time

Javamelody:

Lambdaprobe

Actual situation:

User feedback all kinds of strange problems!

Network access is not connected

Web site, Interface access timeout

Specific features are slow

Part of the function is not open.

.......

-

Ping,telnet,traceroute ....

TOP,TOP-HP pid,jstack pid ....

Jstat-gc,gcutil,gccapacity pid ...

jmap-dump:format=b,file=/opt/.... tail, DF-LH ....

NETSTAT-NATP ....

.....

There is no unified solution to production problems, concrete analysis of specific problems

Memory View: Jstat

Thread condition view: top-hp PID

CPU Views: Jstack

Network views: netstat

Actual problem Analysis:

Online View server condition analysis get memory dump get Javacore

Offline analysis tool debugging analysis Memory threads

Code Debug Eclipse Class decompiler (Auto-decompile, select Jd-core, exact number of rows)

...

Reprint Please specify: http://lawson.cnblogs.com

The above is the actual production problem of their own written ppt,copy down, the JDK comes with the tools and instructions are relatively strong, this article is not too much introduction.

Java Runtime problem Diagnostics-Tools Application

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.