sta*_*max 6 java java.util.concurrent threadpool threadpoolexecutor
我在Spring中使用ThreadPoolTaskExecutor来安排我的任务.
有没有办法获得该任务执行器/池的每个运行和排队线程的列表或内容?
也许不是很优雅,但这样我可以从已知的执行器(使用前缀startsWith())获取所有线程。
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (Thread thread : threadSet) {
if (thread.getName().startsWith("MyExecutor")) {
System.out.println(thread.getName() + " " + thread.getState());
for (StackTraceElement s : thread.getStackTrace()) {
System.out.println(s);
}
}
}
Run Code Online (Sandbox Code Playgroud)
感谢 Surveon 的提示,我赞成他获取排队线程的方法。
| 归档时间: |
|
| 查看次数: |
5899 次 |
| 最近记录: |