//: ThreadInfo.java
public class ThreadInfo{
public static void main(String[] args){
Thread[] threads = new Thread[4];
ThreadGroup tGroup = new ThreadGroup("MyThreadGroup");
if( args.length > 0) {
Thread aThread = Thread.currentThread();
aThread.setName(args[0]);
}
for ( int i=0; i<4; i++ )
{
threads[i] = new Thread(tGroup,"MyThread#" + i);
threads[i].start();
}
ThreadInfo.printAllThreadInfo();
}
// list information about all the threads and threads and
// in the application
public static void printAllThreadInfo(){
ThreadGroup parent,root;
// find the root of all runngin threads
root = parent = Thread.currentThread().getThreadGroup();
while((parent = parent.getParent()) != null)
root = parent;
// print information recursively from the root
System.out.println();
printThreadGroupInfo("",root);
}
// print information about a thread group
public static void printThreadGroupInfo(String indent, ThreadGroup tGroup){
if ( tGroup == null ) return;
System.out.println(indent +
"Thread Group:" + tGroup.getName() +
";Max Priority: " + tGroup.getMaxPriority() +
(tGroup.isDaemon()?"[Daemon]":""));
// print information about component threads
int no_of_threads = tGroup.activeCount();
Thread[] threads = new Thread[no_of_threads];
no_of_threads = tGroup.enumerate(threads,false);
for ( int i=0; i<no_of_threads; i++ )
printThreadInfo(indent + " " , threads[i]);
// print information about component thread groups
int no_of_groups = tGroup.activeGroupCount();
ThreadGroup[] groups = new ThreadGroup[no_of_groups];
no_of_groups = tGroup.enumerate(groups,false);
for ( int i=0; i<no_of_groups; i++ )
printThreadGroupInfo(indent+" ", groups[i]);
}
public static void printThreadInfo(String indent, Thread aThread){
if ( aThread == null ) return;
System.out.println(indent +
"Thread: " + aThread.getName() +
";Priority: " + aThread.getPriority() +
(aThread.isDaemon()?"[Daemon]":"") + (aThread.isAlive()?"[Alive]":""));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
线程实例.rar (24个子文件)
线程池.rar 8KB
线程实例
MethodTest.java 1KB
ThreadInfo.java 2KB
TestDll.java 275B
Pipe.java 1KB
Grp.java 700B
Crunch.java 491B
ProductAndCustom.java 1KB
SimpleRunnable.java 434B
FlagComm.java 1KB
Mythread.java 443B
WaitComm.java 1KB
SimpleThread.java 553B
ThreadA.java 1KB
ThreadStateDemo.java 527B
DeadLocker.java 1KB
MyClock.java 2KB
Crunch2.java 569B
ThreadDemo.java 1KB
Test.java 2KB
Dining.java 1KB
Okay.java 94B
Synch.java 975B
Console.java 1KB
共 24 条
- 1
nicaiwa
- 粉丝: 46
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页