类DaemonThread扩展Thread {
public void run() {
System.out.println("Entering run method");
try {
System.out.println("In run Method: currentThread() is"
+ Thread.currentThread());
while (true) {
try {
Thread.sleep(500);
} catch (InterruptedException x) {
System.out.println("hi");
}
// System.out.println("In run method: woke up again");
finally {
System.out.println("Leaving run1 Method");
}
}
} finally {
System.out.println("Leaving run Method");
}
}
public static void main(String[] args) {
System.out.println("Entering main Method");
DaemonThread t = new DaemonThread();
t.setDaemon(true);
t.start();
try {
Thread.sleep(900);
} catch (InterruptedException x) {}
System.out.println("Leaving main method");
}
}
Run Code Online (Sandbox Code Playgroud)
为什么第二个终于方法没有运行...因为我知道最后方法必须要运行任何条件是..但在这种情况下只有第一个最终方法,为什么不第二个最终运行.
| 归档时间: |
|
| 查看次数: |
1148 次 |
| 最近记录: |