一:获取当前项目所有线程
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 }