Creating a thread as a daemon in Java is as simple as calling the setDaemon() method.
A setting of true means the thread is a daemon; false means it is not. By default, all threads are created with an initial value of false.
Java Daemon Thread Example
- You can make any java thread as daemon thread. Daemon threads acts like service providers for other threads running in the same process.
- Daemon threads will be terminated by the JVM when there are none of the other threads running, it includes main thread of execution as well.
- To specify that a thread is a daemon thread, call the setDaemon() method with the argument true.
- To determine if a thread is a daemon thread, use the accessor method isDaemon().
Have a go - run the script above and you will be able to answer this question :)
No comments:
Post a Comment