How do I create a thread dump of a Java Web Start application
-
01-07-2019 - |
Question
Is it possible to get a thread dump of a Java Web Start application? And if so, how?
It would be nice if there were a simple solution, which would enable a non-developer (customer) to create a thread dump. Alternatively, is it possible to create a thread dump programmatically?
In the Java Web Start Console I can get a list of threads by pressing 't' but stacktraces are not included.
If answers require certain java versions, please say so.
Solution
In the console, press V rather than T:
t: dump thread list
v: dump thread stack
This works under JDK6. Don't know about others.
Alternative, under JDK5 (and possibly earlier) you can send a full stack trace of all threads to standard out:
Under Windows: type ctrl-break in the Java console.
Under Unix: kill -3 <java_process_id>
(e.g. kill -3 5555). This will NOT kill your app.
One other thing: As others say, you can get the stacks programatically via the Thread
class but watch out for Thread.getAllStackTraces()
prior to JDK6 as there's a memory leak.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6434648
Regards,
scotty
OTHER TIPS
Recent JDKs (sadly not JREs) include tools like jstack which does such things. JVMs from version 5 include JMX extensions to get thread dumps, memory statistics, and much more. All java applications, including web start applications, have this functionality available.
You would either need to have the JDK installed or to write a JMX client that does the same thing. Take a look at http://java.sun.com/javase/6/docs/technotes/guides/management/ to get more information.
Since 1.5 you can use Thread.getAllStackTraces()
to get a Map
to iterate over.
The ideal output would be that produced from Ctrl-\ (or Ctrl-Break or similar), but there doesn't seem to be a documented way of producing this. If you are willing to limit yourself to sun's JVM (or use reflection I suppose) you could have a dig around the sun.*
packages and see if anything interesting shows up.
Try
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
Then you can iterate over the collection to show the top x stack elements you're interested in.
Since Java 5 you have the getStackTrace() method of Thread class. For prior versions you can do:
Thread.currentThread().dumpStack();
This will print the stack trace to System.out