Kbase 20026: How to generate a Java Stack Trace
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/12/2008 |
|
Status: Verified
GOAL:
How to generate a Java Stack Trace
GOAL:
How to produce a Java stack trace
FIX:
A Java stack trace is a user-friendly snapshot of the threads and monitors in a Java Virtual Machine (JVM). Depending upon the complexity of your application or applet, a stack trace can range from fifty lines to thousands of lines of diagnostics.
There are three popular ways to generate a Java stack trace:
1) Sending a signal to the Java Virtual Machine.
On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. For example, on a Solaris system, you can use the command kill -QUIT process_id, where process_id is the process number of your Java program.
Alternatively, you can enter the key sequence <ctrl>\ in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads and monitors inside the JVM.
To generate a stack trace on Windows 95, or Windows NT platforms, enter the key sequence <ctrl><break> in the window where the Java program is running, or click the Close button on the window.
2) The Java Virtual Machine generates a stack trace for you.
If the JVM experienced an internal error, for example a segmentation violation or an illegal page fault, it will call its own signal handler to print out the threads and monitors information.
3) Using debugging tools or Java API calls.
You can generate a partial Java stack trace, which in this case is only the threads information, by using the Thread.dumpStack method, or the printStackTrace method of the Throwable class. You can also obtain similar information by entering the command "where" inside the Java debugger.