Java 获取所有线程
作者:
西贝巴巴 | 来源:发表于
2021-03-17 08:47 被阅读0次package com.company;
/*
使用 getName() 方法获取所有正在运行的线程
*/
public class GetNameTest extends Thread {
public static void main(String[] args) {
GetNameTest g = new GetNameTest();
g.setName("thread1");
g.start();
ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
int noThreads = currentGroup.activeCount();
Thread[] lstThreads = new Thread[noThreads];
currentGroup.enumerate(lstThreads);
for (int i = 0; i < noThreads; i++) {
System.out.println("线程号:" + i + " = " + lstThreads[i].getName());
}
}
}
本文标题:Java 获取所有线程
本文链接:https://www.haomeiwen.com/subject/xtlcqltx.html
网友评论