62,634
社区成员




public static String[] getThreadNames() {
ThreadGroup group = Thread.currentThread().getThreadGroup();
ThreadGroup parent = null;
while ( (parent = group.getParent()) != null ) {
group = parent;
}
Thread[] threads = new Thread[group.activeCount()];
group.enumerate(threads);
java.util.HashSet set = new java.util.HashSet();
for (int i=0; i < threads.length; ++i) {
if (threads[i] != null && threads[i].isAlive()) {
try {
set.add(threads[i].getThreadGroup().getName()+","
+threads[i].getName()+","
+threads[i].getPriority());
} catch (Throwable e) {e.printStackTrace();}
}
}
String[] result = (String[]) set.toArray(new String[0]);
java.util.Arrays.sort(result);
return result;
}
void list(PrintStream out, int indent) {
int ngroupsSnapshot;
ThreadGroup[] groupsSnapshot;
synchronized (this) {
for (int j = 0 ; j < indent ; j++) {
out.print(" ");
}
out.println(this);
indent += 4;
for (int i = 0 ; i < nthreads ; i++) {
for (int j = 0 ; j < indent ; j++) {
out.print(" ");
}
out.println(threads[i]);
}
ngroupsSnapshot = ngroups;
if (groups != null) {
groupsSnapshot = Arrays.copyOf(groups, ngroupsSnapshot);
} else {
groupsSnapshot = null;
}
}
for (int i = 0 ; i < ngroupsSnapshot ; i++) {
groupsSnapshot[i].list(out, indent);
}
}