开发者

Can you suspend a Java app and get a snapshot of it's threads from within the app?

开发者 https://www.devze.com 2023-01-02 13:37 出处:网络
I\'m looking at writing moni开发者_如何学Pythontoring code that runs inside a Java application and periodically takes a snapshot of running threads and displays some call stack information on each.

I'm looking at writing moni开发者_如何学Pythontoring code that runs inside a Java application and periodically takes a snapshot of running threads and displays some call stack information on each.

Ideally this would be extended for profiling and/or monitoring.

I don't want to use an external tool, as this is for self educational purposes.


Have you tried Thread.getAllStackTraces()


Take a look at ThreadMXBean.dumpAllThreads(boolean, boolean)

ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] info = bean.dumpAllThreads(true, true);


Have you looked into the methods of the Thread class such as Thread.enumerate(), Thread.activeCount(), Thread.getName() ?


You could register the threads you want to watch at creation time, and have a separate metrics thread to do the monitoring. You would want to build certain metrics into the thread, such as maybe a list of recent running times, current throughput, or other sorts of metrics.


kill -SIGQUIT {java_process}

will dump all stack traces in the stdout of the java process.

0

精彩评论

暂无评论...
验证码 换一张
取 消