2015-04-20 15:36:01 -07:00
|
|
|
//: concurrency/DaemonsDontRunFinally.java
|
|
|
|
// Daemon threads don't run the finally clause
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
import static net.mindview.util.Print.*;
|
|
|
|
|
|
|
|
class ADaemon implements Runnable {
|
2015-05-05 11:20:13 -07:00
|
|
|
@Override
|
2015-04-20 15:36:01 -07:00
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
print("Starting ADaemon");
|
|
|
|
TimeUnit.SECONDS.sleep(1);
|
|
|
|
} catch(InterruptedException e) {
|
|
|
|
print("Exiting via InterruptedException");
|
|
|
|
} finally {
|
|
|
|
print("This should always run?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class DaemonsDontRunFinally {
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
Thread t = new Thread(new ADaemon());
|
|
|
|
t.setDaemon(true);
|
|
|
|
t.start();
|
|
|
|
}
|
|
|
|
} /* Output:
|
|
|
|
Starting ADaemon
|
|
|
|
*///:~
|