Death of a thread

I just noticed that I am starting a bunch of threads but dont have any provisions for them exiting the run method.

So I am asking if I no longer hold a reference to a thread, will it die before the JVM exits on its own? Off the top of my head I am going to say no because that seems like it would require stoping the thread. And the JVM can not know when its safe to do so!?

Originally posted by Mr. C Lamont Gilbert: I just noticed that I am starting a bunch of threads but dont have any provisions for them exiting the run method.

So I am asking if I no longer hold a reference to a thread, will it die before the JVM exits on its own? Off the top of my head I am going to say no because that seems like it would require stoping the thread. And the JVM can not know when its safe to do so!?

Not exactly sure what you are asking, but if you are asking if the thread objects will be garbage collected, the answer is no. They won't be garbaged collected, because the system still holds a copy of all active threads. In fact, you can still a get reference to all the active threads from the thread class.

Look at the Thread javadoc regarding the daemon setting. The JVM exits when all non-daemon threads complete. That means if a non-daemon thread is running, the JVM has to keep running it even if the main() thread ended long ago. Running threads and all the objects on them can't be collected, I imagine because the magical black box of the thread manager has references to them.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com