Reputation: 11306
I'm looking at writing monitoring 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.
Upvotes: 3
Views: 198
Reputation: 915
kill -SIGQUIT {java_process}
will dump all stack traces in the stdout of the java process.
Upvotes: 0
Reputation: 82579
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.
Upvotes: 1
Reputation: 81074
Take a look at ThreadMXBean.dumpAllThreads(boolean, boolean)
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] info = bean.dumpAllThreads(true, true);
Upvotes: 3