This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Daemon Thread  RSS feed

Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • 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.
Posts: 17
  • Mark post as helpful
  • send pies
  • 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,

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!