类 DaemonThread 扩展线程 {
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");
}
}
为什么第二个 finally 方法不运行...我知道 finally 方法必须必须运行任何条件..但在这种情况下只有第一个 finally 方法,为什么不运行第二个 finally 方法。