• 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

setDaemon method

 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
setDaemon method when set to true causes that thread to be a daemon thread instead of user.
i wrote a code and threads in there were set to daemon, and none of the thread ran. this is fine as threads were set to be daemon.
question is what are we trying to achieve then ? can someone explain ? also i know that if one of the user thread exists the other daemon threads would run. so what's the big deal. what are we trying to achieve.
and second what is the concept of "daemon thread group". what is the group here. daemon is set inidividually for a particular thread. where is the group here ?
i had posted this question and answer is 4 but can someone explain why 4 ?
---------------------------------------
A demon Thread group
1 has only demon threads.
2 can have non demon threads.
3 does not exist after all non demon threads in the group have finished executing.
4 does not exist after all the threads in the group have finished executing.
Answer :4
---------------------------------------
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mark stone:
setDaemon method when set to true causes that thread to be a daemon thread instead of user.
i wrote a code and threads in there were set to daemon, and none of the thread ran. this is fine as threads were set to be daemon.
question is what are we trying to achieve then ? can someone explain ? also i know that if one of the user thread exists the other daemon threads would run. so what's the big deal. what are we trying to achieve.


A daemon thread is more often than not a "background" thread. The most common use for a daemon thread is to do something in the background (like a spell checker in a word processor, for example). The biggest distinction is that, when the application ends, you'd like this thread to automatically end, rather than stopping it explicitly. You could, for example, start a daemon thread to do spell checking as soon as someone starts your word processor application (a user thread). Then, until the user closes the word processor application, your daemon thread will continue to run. As soon as the user closes the word processor (your user thread), the daemon thread will stop without you having to do anything.
Daemon threads are often used in this way. I'm not sure what you mean by a daemon thread group, however. Perhaps someone else can help out with that part.
I hope that helps,
Corey
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mark stone:
setDaemon method when set to true causes that thread to be a daemon thread instead of user.
i wrote a code and threads in there were set to daemon, and none of the thread ran. this is fine as threads were set to be daemon.
question is what are we trying to achieve then ? can someone explain ? also i know that if one of the user thread exists the other daemon threads would run. so what's the big deal. what are we trying to achieve.
and second what is the concept of "daemon thread group". what is the group here. daemon is set inidividually for a particular thread. where is the group here ?
i had posted this question and answer is 4 but can someone explain why 4 ?
---------------------------------------
A demon Thread group
1 has only demon threads.
2 can have non demon threads.
3 does not exist after all non demon threads in the group have finished executing.
4 does not exist after all the threads in the group have finished executing.
Answer :4
---------------------------------------


Continuation from Corey's comment......
Hi
A thread group can be a daemon group. A daemon ThreadGroup is automatically destroyed when it becomes empty. A daemon thread group can have daemon and non-daemon threads/threadGroup within itself.
I hope this helps....
Amish
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ January 28, 2002: Message edited by: Marilyn deQueiroz ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn deQueiroz:

[ January 28, 2002: Message edited by: Marilyn deQueiroz ]



Please correct me if I am wrong....
When I leave the thread to be a daemon thread, it runs for a while, then the Thread Scheduler lets the main to run, the main thread tells itself to yield and then again gives the daemon thread to run since there are no user thread left in our case the main exits, the JVM kills all the daemon threads.
When I comment the thread to be a daemon thread, the program continues forever, because the main always yield itself and let the other thread run.
Am I right, please let me know???
Thanks in advance for your help!!!
Amish
 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the code. as soon as user thread is finished the Daemon thread also dies. that part is understood.
what are Daemon groups ? what groups are we talking about here ?

Originally posted by Marilyn deQueiroz:

[ January 28, 2002: Message edited by: Marilyn deQueiroz ]

 
mark stone
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[QB]thanks for the code. as soon as user thread is finished the Daemon thread also dies. that part is understood.
what are Daemon groups ? what groups are we talking about here ?
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi mark,
this link might be helpful...
Click Here
regards
maulin
 
reply
    Bookmark Topic Watch Topic
  • New Topic