Daemon Thread Concept Simplified in Java

Daemon threads are service threads. Their main objective is to provide different services to other thread.They normally runs in an infinite loop and attain client thread's requesting service when no other thread is present or exists.The Daemon thread automatically exists.JVM does not wait for the death or destroy of Daemon thread before concluding a program.
Here is the code to create a Daemon thread

Thread t=new Thread();
//creates a new thread
//mark the thread as daemon thread
By default,all threads created by Daemon thread are also Daemon thread.
Below are the methods supported by a Daemon thread:

Method Name Returns Description Comments
getName() String returns the nae of the ThreadGroup
setName() void Sets the name of the ThreadGroup
getParent() ThreadGroup returns the parent ThreadGroup of the thread or ThreadGroup
getMaxPriority() int Returns the maximum priority of the ThreadGroup
activeCount() int Returns the active thread of a ThreadGroup
activeGroupCount() int Returns the number of active ThreadGroups in the ThreadGroup
isDaemon() boolean Returns true if the thread is a daemon thread else returns false
setDaemon() void Sets the thread as a daemon thread
Daemon Thread Concept Simplified in Java Daemon Thread Concept Simplified in Java Reviewed by Animesh Chatterjee on September 19, 2018 Rating: 5

No comments:

Powered by Blogger.