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


Tip of the Day
May 31, 2021

Java dumpStack Method

There are times where you might want to better understand the code flow in a particular threaded scenario. Performing this task can be tedious, at best. Fortunately, Java has a mechanism in place to help make this much easier. Today we look at the dumpStack method for current threads.

Here is a sample Java code snippet for using the dumpStack method:

*/

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

	private void proceed()
	{
		System.out.println("In proceed() method.");
		Thread.currentThread().dumpStack();
	}
}

/*

Expected output:

[root@mypc]# java CurrentThreadDumpStack
In proceed() method.
java.lang.Exception: Stack trace
        at java.lang.Thread.dumpStack(Unknown Source)
        at CurrentThreadDumpStack.proceed(CurrentThreadDumpStack.java:21)
        at CurrentThreadDumpStack.main(CurrentThreadDumpStack.java:15)

*/
MS Sridhar
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date