62,616
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
ThreadGroup threadGroup= Thread.currentThread().getThreadGroup().getParent();
//不知道java为什么定义了一个ThreadGroup
Thread[] list=new Thread [threadGroup.activeCount()];
threadGroup.enumerate(list,true);
//enumerate这个做什么用的?
for (Thread thread : list) {
System.out.println(thread.getName()+"优先级:"+thread.getPriority());
}
}
public class AllThread {
public static Thread[] getAllThread() {
ThreadGroup root = Thread.currentThread().getThreadGroup();
ThreadGroup ttg = root;
while ((ttg = ttg.getParent()) != null) root = ttg;
Thread[] tlist = new Thread[(int)(root.activeCount() * 1.2)];
return java.util.Arrays.copyOf(tlist, root.enumerate(tlist, true));
}
public static void main(String[] args) {
Thread[] ts = getAllThread();
for (Thread t : ts) {
System.out.println(t.getId() + ": " + t.getName());
}
}
}
2: Reference Handler
3: Finalizer
4: Signal Dispatcher
5: Attach Listener
1: main