In Effective Java: item 66, Joshua Bloch gave an example about life failure:
// Broken! - How long would you expect this program to run
class StopTh
System.out.println()
requests a resource to write on the console, which in itself a blocking method… meaning, it will block the backgroundThread()
to print()
on the console. This is similar to sending an interrupt to it.
Thus, backgroundThread()
will become aware of the change in the value of the boolean and stop executing, thereby terminating the Daemon.