posted 18 years ago
There are daemon threads and user threads.
When the "main()" method is finished, it can happen that other threads are still running (i.e. not finished their "run()" method). It is easy to think of examples.
If the "main()" method is finished, but other user threads are still runnning, the JVM keeps running until the last user thread is finished running.
If the "main()" method and ALL user threads are finished, but there are still daemon threads running, the JVM stops running. In this case, it terminates the "run()" method(s) of the daemon thread(s) before it/they finish.
This is the only difference. It is just a way to mark a thread as "must finish" (user) or "doesn't have to finish" (daemon).
Often daemon threads are "helper threads" and run in an infinite loop "for( ; ; ) { //code }, so they can never finish their "run()" method. As a daemon thread, an infinite loop is OK, since the thread will end anyway when all user threads are finished.
Do you understand now?
[ July 24, 2006: Message edited by: Douglas Chorpita ]