dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


advertisement
 

Tip: Obtaining a Thread Dump of Your Java App in Linux

Learn how to trigger a thread dump in Java on Linux os.


advertisement

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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);
         }
      }
   }
} 

 

Visit the DevX Tip Bank

 





   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date