Java并发-ThreadGroup获取所有线程
2021-07-09 05:04
标签:[] out name tst while code group span reads 一:获取当前项目所有线程 Java并发-ThreadGroup获取所有线程 标签:[] out name tst while code group span reads 原文地址:https://www.cnblogs.com/java-zzl/p/9567548.html 1 public Thread[] findAllThread(){
2 ThreadGroup currentGroup =Thread.currentThread().getThreadGroup();
3
4 while (currentGroup.getParent()!=null){
5 // 返回此线程组的父线程组
6 currentGroup=currentGroup.getParent();
7 }
8 //此线程组中活动线程的估计数
9 int noThreads = currentGroup.activeCount();
10
11 Thread[] lstThreads = new Thread[noThreads];
12 //把对此线程组中的所有活动子组的引用复制到指定数组中。
13 currentGroup.enumerate(lstThreads);
14
15 for (Thread thread : lstThreads) {
16 System.out.println("线程数量:"+noThreads+" 线程id:" + thread.getId() + " 线程名称:" + thread.getName() + " 线程状态:" + thread.getState());
17 }
18 return lstThreads;
19 }
上一篇:C#异步编程基础入门总结
下一篇:Java中 equals和==
文章标题:Java并发-ThreadGroup获取所有线程
文章链接:http://soscw.com/index.php/essay/102622.html