116
|
A daemon thread is a thread, that does not prevent the JVM from exiting when the program finishes but the thread is still running. An example for a daemon thread is the garbage collection.
You can use the
setDaemon() method to change the Thread daemon properties. | ||||
|
55
|
A few more points (Reference: Java Concurrency in Practice)
| ||||||||||||
|
35
|
I think you mean "daemon" rather than "demon". Traditionally daemon processes in UNIX were those that were constantly running in background, much like services in Windows.
A daemon thread in Java is one that doesn't prevent the JVM from exiting. Specifically the JVM will exit when only daemon threads remain. You create one by calling the
setDaemon() method on Thread .
Have a read of Daemon threads.
| ||||||||
|
15
|
A daemon thread is a thread that is considered doing some tasks in the background like handling requests or various chronjobs that can exist in an application.
When your program only have damon threads remaining it will exit. That's because usually these threads work together with normal threads and provide background handling of events.
You can specify that a
Thread is a demon one by using setDaemon method, they usually don't exit, neither they are interrupted.. they just stop when application stops. | |||
15
|
Daemon threads are like a service providers for other threads or objects running in the same process as the daemon thread. Daemon threads are used for background supporting tasks and are only needed while normal threads are executing. If normal threads are not running and remaining threads are daemon threads then the interpreter exits.
For example, the HotJava browser uses up to four daemon threads named "Image Fetcher" to fetch images from the file system or network for any thread that needs one.
Daemon threads are typically used to perform services for your application/applet (such as loading the "fiddley bits"). The core difference between user threads and daemon threads is that the JVM will only shut down a program when all user threads have terminated. Daemon threads are terminated by the JVM when there are no longer any user threads running, including the main thread of execution.
setDaemon(true/false) ? This method is used to specify that a thread is daemon thread.
public boolean isDaemon() ? This method is used to determine the thread is daemon thread or not.
Eg:
OutPut:
| |||
Thread
javadoc describes what they are: java.sun.com/javase/6/docs/api/java/lang/Thread.html – skaffman Feb 6 '10 at 14:54