×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thread Dump of Your Java App in Linux
 

Submitted by: M S Sridhar(sridhar.ms@gmail.com)

Thursday Nov 9th 2017 by M S Sridhar

Language: Java, Expertise: Intermediate - Learn how to trigger a thread dump in Java on Linux os.

Thread dump is a mechanism to view the various threads active in your application and also to know the current methods that they are active on. The result may not be the same every time you take a thread dump as the state can be different at different intervals.

In Linux, we have the command kill -3 , which will yield a whole lot of details and it is for you to analyze. The following code can run for some time, thereby helping you to trigger a thread dump.

public class LongFile
{
   public static void main(String args[])
   {
      LongFile longFile = new LongFile();
      longFile.proceed();
   }

   private void proceed()
   {
      for(int i=0; i       {
         if (i % 100 == 0)
         {
            try{
            //Trying to make a small sleep to enable you to take the thread dump
               Thread.sleep(1000);
            }catch(InterruptedException ie)
            {
               System.out.println("InterruptedException: "+ ie);
            }
            System.out.println("i: " + i);
         }
      }
   }
} 
Home
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved