- 论坛徽章:
- 0
|
上面程序找到一些错误,改了后的为:
import java.io.*;
public class ThreadInfo{
static PrintWriter out=new PrintWriter(System.out,true);
public static void main(String[] args){
Thread[] thread=new Thread[4];
ThreadGroup group = new ThreadGroup("MyThreadGroup");
if(args.length>0){
thread=Thread.currentThread();
thread.setName(args[0]);
}
for (int i=0;i<4;i++){
thread[i]=new Thread(group,"MyThread#"+i);
ThreadInfo.printAllThreadInfo();
}
public static void printAllThreadInfo(){
ThreadGroup parent,root;
root = parent = Thread.currentThread().getThreadGroup();
while((parent=parent.getParent())!=null)
root=parent;
out.println();
printThreadGroupInfo("",root);
}
public static void printThreadGroupInfo(String indent,ThreadGroup group){
final int SAFRTY = 5;
if(group==null)
return;
out.println(indent+" THREAD GROUP: "+group.getName()
+" ;Max Priority: "+ group.getMaxPriority()+
(group.isDaemon()?"[Daemon]":""));
int numThreads=group.activeCount();
Thread threads[]=new Thread[numThreads+SAFRTY];
numThreads=group.enumerate(threads,false);
for (int i = 0;i<numThreads;i++)
printThreadInfo(indent+"",threads[i]);
int numGroups=group.activeGroupCount();
ThreadGroup groups[]=new ThreadGroup[numGroups+SAFRTY];
numGroups=group.enumerate(groups,false);
for(int i=0;i<numGroups;i++)
printThreadGroupInfo(indent+"",groups[i]);
{
public static void printThreadInfo(String indent,Thread thread){
if(thread==null)
return;
out.println(indent+"THREAD:"+thread.getName()+
(thread.isDaemon()?"[Daemon]":"")+
(thread.isAlive()?"[Alive]":"[NotAlive]")+
((Thread.currentThread()==thread)?"<==current":""));
}
}
}
}
}
但是提示的错误还是一样的 |
|