• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Dameon Threads??

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys:
Can anybody please tell me the difference between a Daemon thread and User thread?? I checked the API it says that when u call setDaemon() method it will set the thread as Daemon thread...and JVM can shut down if the running threads are only Daemon threads...

I am searching a proper definition for it....Can anybody help me?? Thanks


Regards
Swapnil
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Swapnil Trivedi:
...JVM can shut down if the running threads are only Daemon threads...


That's basically it. A Daemon is a background process whose "completion" is not required.
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swapnil,

Daemon thread is at the mercy of java runtime system. JVM can terminate at any time. Whereas user thread will always be successfully terminated.

If no user thread is running, then JVM can terminate daemon thread in between.

you can test above statments by setting a child thread as daemon thread before starting it.

You can see in that case when main terminates, child may terminate even without successful completion.

Whereas, if child thread is user thread, then child will definitely be completed even if main terminates before that.

Each child thread inherits its user status from main thread.

Regards

Naseem
[ June 30, 2006: Message edited by: Naseem Khan ]
 
Swapnil Trivedi
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Naseem and Thanks Marc.


Regards
Swapnil
 
Onion rings are vegetable donuts. Taste this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic