How to get current stack trace in Java for a Thread - Debugging Tutorial

Stack trace is very useful while debugging or troubleshooting any issue in Java. Thankfully Java provides couple of ways to get current stack trace of a Thread in Java, which can be really handy in debugging. When I was new to Java programming, and didn’t know how to remote debug a Java application, I used to put debug code as patch release, which uses classpath to pick debug code for printing stack trace and shows how a particular method is get called and that some time provide vital clue on missing or incorrect argument. Now, When I have couple of Java debugging tips at my sleeve, I still think knowledge of  how to get current stack trace in Java for any Thread, or simply print stack trace from any point in code worth knowing. For those who are not very familiar with stack trace and wondering what is stack trace in Java, here is quick revision. Thread executes code in Java, they call methods, and when they call, they keep them in there stack memory. You can print that stack trace to find out, from where a particular method is get called in execution flow. This is especially useful if you are using lot of open source libraries, and don’t have control on all the code. One of the most familiar face of stack trace in Java is printing stack trace using Exception.printStackTrace(), when an Exception or Error is thrown in Java. In this Java tutorial, we will look at couple of ways to print and get current stack trace of a Thread in Java.
Read more »

0 Response to "How to get current stack trace in Java for a Thread - Debugging Tutorial"

Posting Komentar