Some simple debugging tools related to Java. These are for those who are new to Java.
1. Application is crashing : Most miserable one. Get your log file, try to analysis log. How to write log file, use Java Logger API. Java Logger had been introduced in JDK 1.4.2. The most awesome feature of Logger API is that you can use it in production without much overhead. The overhead is controlled by something called level in API. Level goes from FINEST to SEVERE. You can refer to O'Relly Book "Java, In a NutShell". I guess, it covers Logging API into a great detail.
Lot many things to know: Standalone application is crashing or web application. Its crashing with -client or -server option, appletviewer or browser, plugin or plugin2.
2. Application Hang: Most prominent reason for Hang is thread related. I don't know too many language but Java handles thread in most graceful way. What we can do when a Java Process or Application Hang:
- Hmm, get stack trace at Java and native level.
- Get to know current thread conditions and their status.
- Try to get core dump. Sometime, application will refuse to give you.
- Get to know machine detail. Almost all OS, use different thread model. Not only that in Solaris, 8 and 9 use different models. Sometime, it narrow down the problem, if you are luck :).
How to get all these information. Easy actually. Take help of Java Debugger, jdb(which is a part of JDK). In jdb, you can run the command like threads, thread, dump and many more. Take help of Windbg, if its a windows machine for native level. I find it useful and painful.
3. Your application is drinking memory: There is some memory leak. Best is to use jhat(part of JDK). First take a heap dump by using jmap, jconsole hprof. Pass that heap dump to jhat and it will bring a server and
dump all the information. Analyze where most of the memory is going. Writing to track the place from where memory is going. What is GC response on it. Change some arguments of GC and then give a try.
There are lot of JDK tools that help in analyzing JVM, threads, memory, process. See the list : http://java.sun.com/javase/6/docs/technotes/tools/
Garbage collector play important role in all of them, so always get to know what is best for what:- http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html (Even you know less about GC, you can't resist yourself finishing this page, this is so interesting). In terms of GC, everything is improving day be day and we have new GC, Garbage First aka G1 ready. With Vikram, I had one presentation on G1 in Sun tech days - http://developers.sun.com/events/techdays/presentations/locations-2009/hyderabad/td_hyd_garbagcollector_aroskar_choudhary.pdf.
If you have any wired debugging story related to Java, please share :). Also, visit Visual VM which is meant to integrate all the command line tools of JDK.
1 comment:
Good article
Writers often face problems like entering same matter again and again because it may not necessary be handy. However you can convert your scanned pages (jpeg/tiff/pdf) on http://www.onlinedocumentconversion.com/ and convert online. No need to reenter or repeat text matter again.
I feel even if you have to pay a little bit it’s worth it, because paid sites are definitely better then unpaid sites.
Caution!
Avoid free sites or sites with no after sales support is a NO NO.
Post a Comment