Home » Tip Bank » Java » Threading
  • Email Article
  • Comment on this Article
  • Share Article
    • Digg
    • del.icio.us
    • Newvine
    • furl
    • StumbleUpon
    • BlinkList
    • Newsvine
    • Magnolia
    • Facebook
    • Tailrank
    • Slashdot
    • Technorati
    • Google Bookmarks
    • Yahoo Favorites
    • Windows Live
    • Ask
Language: Java
Expertise: Intermediate
Nov 9, 2017

WEBINAR: On-Demand

Unleash Your DevOps Strategy by Synchronizing Application and Database Changes REGISTER >

Obtaining a Thread Dump of Your Java App in Linux

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);
         }
      }
   }
} 
M S Sridhar
 
Submit a Tip
Browse "Java" Tips
Browse All Tips
w3.org
w3schools.com