Alex Rivera | Logout

Generate a Java thread dump without restarting.

Asked 2012-10-11T14:48:29.933
10

I'd like to create a thread that keeps track of the memory usage and cpu usage.

If the application reaches a high level, I want to generate an heap dump or a thread dump.

Is there a way to generate a Thread dump runtime without restarting?

Edit
Report

1 Answer

10

To dump the threads to the standard out, you may do something like this

ThreadInfo[] threads = ManagementFactory.getThreadMXBean()
        .dumpAllThreads(true, true);
for (ThreadInfo info : threads) {
    System.out.print(info);
}

in Java 6 using the ThreadMXBean class. But I would suggest to use real logging instead of the standard output.

answered 2012-10-11T14:55:02.940

Your Answer