hi ganshre,
JVM treats threads as either non Daemon user threads or Daemon threads. A thread can be set to Daemon status by
1. Using the method setDaemon(true) before the thread is started via start() method call.
2. When a Daemon thread creates a new thread the new thread automatically inherits the Daemon status of its parent thread. In this case a setDaemon(true) call is not required for making the thread Daemon.In other words, all threads created by Daemon threads will be Daemonss!!!
When an application is started, the main method thread is executed as a user thread and if there are no other user threads created by the main method the application will exit once the main method thread is completed.
If JVM finds out that only Daemon threads are running in the application, (ie all the user threads are stopped) JVM will close down the application and exit.
The main advantage of Daemon threads are that they are automatically killed by the JVM once no other threads are existing. We don't need to worry about stopping the Daemon threads. But be careful not to assign any important tasks in Daemon threads as Daemons may end abruptly without your consent once all other threads are stopped and thereby creating havoc.
Hope I have made it somewhat clear...
Kalidas.