Threads of Control |
Any Java thread can be a daemon thread. Daemon threads are service providers for other threads running in the same process as the daemon thread. 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. Therun()
method for a daemon thread is typically an infinite loop that waits for a service request.When the only remaining threads in a process are daemon threads, the interpreter exits. This makes sense because when only daemon threads remain, there is no other thread for which a daemon thread can provide a service.
To specify that a thread is a daemon thread, call the
setDaemon()
method with the argumenttrue
. To determine if a thread is a daemon thread, use the accessor methodisDaemon()
.
Threads of Control |