daemonexam.java
来自「Java程序设计实用教程源代码 本书源代码按章分别放置在不同的文件夹中,所有程」· Java 代码 · 共 33 行
JAVA
33 行
class Daemon extends Thread {
private static final int SIZE = 10;
private Thread[] t = new Thread[SIZE];
public Daemon() {
setDaemon(true);
start();
}
public void run() {
for (int i = 0; i < SIZE; i++)
t[i] = new DaemonSpawn(i);
for (int i = 0; i < SIZE; i++)
System.out.println("t[" + i + "].isDaemon() = " + t[i].isDaemon());
while (true)
yield();
}
}
class DaemonSpawn extends Thread {
public DaemonSpawn(int i) {
System.out.println("DaemonSpawn " + i + " started");
start();
}
public void run() {
while (true)
yield();
}
}
public class DaemonExam {
public static void main(String[] args) {
Thread d = new Daemon();
System.out.println("d.isDaemon() = " + d.isDaemon());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?