Can any one explain me what r Daemon Thread. Well i have read that Daemon thread dies when the thread taht created them dies, and if a thread is a daemon then any thread it creats will automatically be daemon. But i can't actually understand what this Daemon is, how can v invoke them. thank u.
Hi Umang, The JVM distinguishes threads as 2 types, daemon threads and non-daemon threads. Daemon thread is one that is subordinate to the thread which created it. Daemon threads are described in various ways as 'attendant', 'helper' or 'background' threads. A daemon thread cannot do anything on its own unless used by another non-daemon (user thread). Bill Venners explains the difference between the 2 types of threads clearly in his book "Inside the Java Virtual Machine": "Inside the Java Virtual Machine, threads come in two flaovors: daemon and non-daemon. A daemon thread is ordinarily used by the virtual machine itself, such as a thread that performs garbage collection. The application, however, can mark any threads it creates as daemon threads. The initial thread of an application - the one that begins at main() - is a non-daemon thread. A Java application continues to execute (the virtual machine instance continues to live) as long as any non-daemon threads are still running. When all non-daemon threads of a Java application terminate, the virtual machine instance will exit. If pemitted by the security manager, the application can also cause its own demise by invoking the exit() method of class Runtime or System". To set a thread as 'daemon' type, we call the setDaemon() method before calling the thread's start() method. Changing the status of a thread already started throws IllegalThreadStateException. The setDaemon() method in turn calls the checkAccess() method to verify if the currently running thread has permission to modify this thread. The start() method of Thread class can be used for starting the daemon thread. Hope this clarifies your query. Best wishes, Balu
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Programmatically Create PDF Using Free Spire.PDF with Java