Every now and then I end up looking at ways to improve our use and handling of the various threads that are used internally. With this in mind I decided that I would write an article covering useful practices for java threads that should become second nature to all who have to deal with threads on a regular basis.
Daemon threads can be thought of as background threads. They sit in the background working away at a task whilst the program is still running. When I refer the the program I mean there is a non-daemon thread currently running as when all non-daemon threads are running the program will close. Should this happen then all daemon threads will be halted, anything being executed will “drop out” this means that finally bloack will not even be executed so it is important to ensure that daemon thread do not contain anything that will cause harm if the execution is just ended without warning.