Java TroubleShooting Tools

I have been working with a lot (when i mean a lot ~50++) of threads. It is necessary for our applications because we deal with a lot (~millions of records). Why is it necessary to multi-thread ?
Let's say you have 1,000,000 records to process and each records is processes roughly about 5 seconds (really intense processing e.g. calling web services, writing xml, uploading via ftp). It will take you roughly 57 days, 20 hours, 53 minutes, 20 seconds to process all of the records (5,000,000 seconds).
Since you are dependent on other systems (e.g. like web services to process the records) you can't really ask the publisher of the service to speed things up (unless you have are willing to throw in time and effort into the service before you process your records). So, enter multi threading.
Multi Threading - enables you to leverage the multiple processors (common to most enterprise server level boxes) to process records in parallel. BUT- multi threaded programs are really hard to write (specially in java (I pity you if you are still using java 1.4 for multi threaded applications)). In java 1.5 and higher the java.util.concurrent package makes it a little bit easier for java programmers to multi- thread. Even though the concurrent package makes it easy, you will still encounter issues with multi thread programs (e.g. deadlocks, synchronization).  The experimental trouble shooting tools that came with java 1.6 will help find those issues. Here are the tools that have been helpful for me:
(Note: all sample commands are java on a unix based machine (java 1.6 on suse) pid= java process id)
1. jstack 
      jstack -l
      This prints a Java stack traces of Java threads for a given Java process or core file or a remote debug server.
         I really like the option l because it prints information about locks
2. jmap
    jmap -heap
     This prints a heap summary. When you are running multi-threads, you better make sure you have enough memory for the objects that each thread needs.
3. jinfo
      jinfo
       Prints all system properties, including those -D that comes with the java command line. Really helpful when threads are running in a container.

That is just the tip of the iceberg when trouble shooting java processes.
If you want more follow this link --> Trouble Shooting Java SE

Comments

Popular posts from this blog

OAuth 1.0a Request Signing and Verification - HMAC-SHA1 - HMAC-SHA256

Spark DataFrame - Array[ByteBuffer] - IllegalAurmentException

Gensim Doc2Vec on Spark - a quest to get the right Vector