What is the sense of Thread.setDaemon() method?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sergei_Istomin
Posted On:   Tuesday, July 30, 2002 09:07 PM


What is the sense of using Thread.setDaemon() method?
I create a Thread in main() method, set it's daemon status using setDaemon(true) and start it. But when JVM exits the daemon exits too. How can I create a daemon process?

Re: What is the sense of Thread.setDaemon() method?

Posted By:   Gautam_Marwaha  
Posted On:   Tuesday, July 30, 2002 09:33 PM

The main thread (JVM) waits for all threads (started within the process) to exit before it exits. However, if you mark any created threads as daemon, the JVM no longer waits for those threads to exit. Instead it goes ahead and exits and as a result those daemon threads also exit (no threads can keep running if the process which started them has exited).

In java, creating daemon process running in the background is possible if a class runs in a infinite loop and is started using javaw.

About | Sitemap | Contact