Java学习笔记之线程isAlive⽅法isAlive⽅法:
⽅法isAlive()功能是判断当前线程是否处于活动状态。
活动状态就是线程启动且尚未终⽌,⽐如正在运⾏或准备开始运⾏。
public class IsAliveThread extends Thread {
public IsAliveThread() {
System.out.println("begin");
System.out.println("Thread.currentThread().getName() : " + Thread.currentThread().getName());
System.out.println("Thread.currentThread().isAlive() : " + Thread.currentThread().isAlive());
System.out.println("Name() : " +  Name());
System.out.println("this.isAlive() : " + this.isAlive());
System.out.println("end");
}
@Override
public void run() {
System.out.println("run begin");
System.out.println("Thread.currentThread().getName() : " + Thread.currentThread().getName());
System.out.println("Thread.currentThread().isAlive() : " + Thread.currentThread().isAlive());
System.out.println("Name() : " +  Name());
System.out.println("this.isAlive() : " + this.isAlive());
System.out.println("run end");
}
}
public class ThreadRunMain {
public static void main(String[] args) {
testIsAliveThread();
}
public static void testIsAliveThread(){
IsAliveThread ist = new IsAliveThread();
Thread th = new Thread(ist);
System.out.println("Main begin th isAlive = " + th.isAlive());
th.start();
System.out.println("Main end th isAlive = " + th.isAlive());
}
学习java的学习方法
}
运⾏结果:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。