Generate a Java thread dump without restarting.

后端 未结 5 1388
别跟我提以往
别跟我提以往 2020-12-06 18:13

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

5条回答
  •  北海茫月
    2020-12-06 18:28

    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.

提交回复
热议问题