一:獲取當前項目所有線程
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 }