Anyone have taken the test, could you tell me whether the Daemon thread appeared in the test? I am not familar with it and I will take the test tomorrow, so .....? Or somebody can give me a hand about this? Thank you very much! Shirley!
It is simple. When a thread t1 create another thread t2, and it designates that t2 is daemon thread, as soon as t1 dies, t2 also dies. If it is not designated as daemon thread, t2 continue live as long as it needs to beyond the life of t1. That is my recollection. I could not find it the books I have in front of me now. I do not if this is in the scope of exam or not.
Daemon threads are no different from any other thread, except that they have a flag set which says "I am a daemon". This only matters to the VM for deciding when it's time to shutdown. Whenever a thread dies, the VM looks to see if there are any non-daemon threads still alive. If so, it stays up, otherwise it shuts down. The classic daemon thread is the garbage collector. It's always alive, but when all "user" (non-daemon) threads have died, it doesn't prevent the VM from shutting down.