Created
January 4, 2020 21:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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