获取当前在Java中运行的所有线程的列表 [英] Get a List of all Threads currently running in Java

查看:1141
本文介绍了获取当前在Java中运行的所有线程的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以获得当前JVM中所有正在运行的Thread的列表(包括我的类未启动的Threads)?

Is there any way I can get a list of all the running Threads in the current JVM (including the Threads NOT started by my class)?

是否也可以获取列表中所有线程的Thread和Class对象?

Is it also possible to get the Thread and Class objects of all Thread in the list?

我希望能够通过代码完成此任务。

推荐答案

获取可迭代集:

Set<Thread> threadSet = Thread.getAllStackTraces().keySet();

这篇关于获取当前在Java中运行的所有线程的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆