QQ网名大全

j**a 根据线程名字查询一个线程,能实现吗?

根据线程名称找到线程,在j**a中是可以实现的,实现步骤是:
1、首先获取J**a VM中当前运行的所有线程
以下代码是用数组返回J**a VM中当前运行的所有线程
public static Thread[]findAllThreads()
{
ThreadGroup group=Thread.currentThread().getThreadGroup();ThreadGroup topGroup=group;遍历线程组树,获取根线程组*/
while(group!null)
{
topGroup=group;group=group.getParent();}
激活的线程数加倍*/
int estimatedSize=topGroup.activeCount()*2;Thread[]slackList=new Thread[estimatedSize];获取根线程组的所有线程*/
int actualSize=topGroup.enumerate(slackList);copy into a list that is the exact size*/
Thread[]list=new Thread[actualSize];System.arraycopy(slackList,0,list,0,actualSize);return(list);}2、遍历线程,比对名称,找到需要寻找的线程
以下代码可得到线程的名称
String name=thread.getName();
佚名
2024-06-05 08:46:16
最佳回答
类似问题(10)