• 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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.
 
Greenhorn
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,
Balu

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!