Originally posted by Peter Chase:
Because a daemon thread may exit at any point in its code, you have to be careful what types of things it does.
For example, it is probably a bad idea for a daemon thread to do file-writing. The thread might exit at any point during the write, leaving the file in a part-written, corrupt state. Unless the file is a temporary file used only during a single run of the application, you don't want that.
You could create some kind of lock. If there is a critcal section of code, ran by a daemon thread, it can lock the VM to prevent it from exiting during this critical section. This will allow background saves to be done by daemon threads.
BTW, there is no black magic here. To prevent the JVM from exiting, just create another user thread -- which simply waits til it is told to complete.
Henry