• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Daemon Thread

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic