twothreadalive.java
来自「Java Thread Programming (Source」· Java 代码 · 共 31 行
JAVA
31 行
public class TwoThreadAlive extends Thread {
public void run() {
for ( int i = 0; i < 10; i++ ) {
printMsg();
}
}
public void printMsg() {
// get a reference to the thread running this
Thread t = Thread.currentThread();
String name = t.getName();
System.out.println("name=" + name);
}
public static void main(String[] args) {
TwoThreadAlive tt = new TwoThreadAlive();
tt.setName("my worker thread");
System.out.println("before start(), tt.isAlive()=" + tt.isAlive());
tt.start();
System.out.println("just after start(), tt.isAlive()=" + tt.isAlive());
for ( int i = 0; i < 10; i++ ) {
tt.printMsg();
}
System.out.println(
"at the end of main(), tt.isAlive()=" + tt.isAlive());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?