宗策

导航

获取线程相关信息的方法

package seday08.thread;
/**
* @author xingsir
* 获取线程相关信息的方法
*/
public class ThreadInfoDemo {

public static void main(String[] args) {
//主线程
Thread main=Thread.currentThread();
System.out.println(main);
//线程的唯一标识
long id=main.getId();
System.out.println(id);
//线程名字
String name=main.getName();
System.out.println(name);
//线程的优先级
int priority = main.getPriority();
System.out.println(priority);
//线程是否处于活动状态
boolean isAlive = main.isAlive();
System.out.println("isAlive:"+isAlive);
//线程是否为守护线程
boolean isDaemon = main.isDaemon();
System.out.println("isDaemon:"+isDaemon);
//线程是否被中断
boolean isInterrupted = main.isInterrupted();
System.out.println("isInterrupted:"+isInterrupted);
}

}

posted on 2019-12-18 15:50  宗策  阅读(341)  评论(0编辑  收藏  举报