📄 isalivedemo.java
字号:
package chapter13;
public class IsAliveDemo extends Thread {
public IsAliveDemo(String str) {
super(str); // 调用其父类的构造方法
}
public void run() {
System.out.println(getName() + "运行中。。。");
}
public static void main(String args[]) {
IsAliveDemo t = new IsAliveDemo("线程");
t.start();
if (t.isAlive()) {
System.out.println("线程处于活动的状态!");
} else {
System.out.println("线程已经终止!");
}
try {
t.join(); // 等待线程终止,这里有可能发生中断异常
} catch (InterruptedException e) {
e.printStackTrace();
}
if (t.isAlive()) {
System.out.println("线程处于活动的状态!");
} else {
System.out.println("线程已经终止!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -