Skip to content

Instantly share code, notes, and snippets.

@cleantutorials
Created January 4, 2020 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleantutorials/7f8cba2bb44a951bcf5273989d1eacbd to your computer and use it in GitHub Desktop.
Save cleantutorials/7f8cba2bb44a951bcf5273989d1eacbd to your computer and use it in GitHub Desktop.
An example program to demonstrate what a stack trace looks like. The stack trace for the main thread is in the comments.
public class StackTraceExample {
public static void main(String[] args) {
StackTraceExample example = new StackTraceExample();
example.method1();
}
public void method1() {
method2();
}
public void method2() {
method3();
}
public void method3() {
try {
Thread.sleep(500000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/*
Stack Trace of Main Thread from JConsole:
java.lang.Thread.sleep(Native Method)
StackTraceExample.method3(StackTraceExample.java:18)
StackTraceExample.method2(StackTraceExample.java:13)
StackTraceExample.method1(StackTraceExample.java:9)
StackTraceExample.main(StackTraceExample.java:5)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment