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

Demon ThreadGroup/ThreadGroup

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
Please someone help me these to understand these two things Demon ThreadGroup/ThreadGroup. I really don't know what are the similerties and differneces between them? why do we need two type of thread group? beacuse somewhere i read that demon threadgroup can also have non demon threads.
Please help me. i would really appreciate your effort.
Thanks in advance.
vivek
 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi ,
Rahul did answer to my question in some other thread ( which I had started). Still I have some questions/confusions.
He said



Hi Vivek,
A daemon thread group can be creaed using the setDaemon(true) method of the ThreadGroup class. A group's daemon status applies only to the group. Changing a group's daemon status does not affect the daemon status of any of the threads in the group. Furthermore, a group's daemon status does not in any way imply the daemon status of its threads--you can put any thread within a daemon thread group.
The daemon status of a thread group simply indicates that the group will be destroyed when all of its threads have been terminated. Thus a daemon thread group can have both user and daemon threads. Hope this answers two of u r multiple choice answers
1. has only demon threads. (False)
// can have user threads also.
2. can have non demon threads. (True)
// yes see explanation above
3. does not exist after all non demon threads in the group have finished executing. (False)
//will continue to exist till all daemon threads and user threads are executing
4. does not exist after all the threads in the group have finished executing. (True)
// look at answer above
regds.
Rahul


My question are
1. Why do we create ThreadGroup?
2. Can�t we have both type of threads(demon/non-demon) in simple a ThreadGroup?
3. When it does not exist?
4. Any other thing do u think I should know please let me know about simple ThreadGroup.
5. Why do we create Demon ThreadGroup? ( may be this is related to the answer of question #2 because if we can�t have both type of threads in simple ThreadGroup then we may need to create demon ThreadGroup. Just guessing.)
6. Why does it contain both types of thread ? if simple ThreadGroup can�t have demon threads.
May be I am going out of limit but your help would help me to understand the concept properly. I would really appreciate your effort.
I had tried to understand these things from book. I didn�t work out. So please don�t refer me to a link. Please give me a bit of your valuable time.
Thanks in advance.
vivek


[This message has been edited by Vivek Shrivastava (edited July 19, 2000).]
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Let me try...
1. Why do we create ThreadGroup?
ThreadGroups are logical ways of grouping related threads. Every threads belong to a threadgroup. After grouping the threads, you can perform various actions on all the threads involved in the group. If your program is heavily multi-threaded, then ThreadGroups might offer you better manageability and some kind of cleaner design.
2. Can�t we have both type of threads(demon/non-demon) in simple a ThreadGroup?
Absolutely you can.
3. When it does not exist?
ThreadGroups always exist. There is atleast one threadgroup called main, which happens to be the default threadgroup the threads belong to.
4. Any other thing do u think I should know please let me know about simple ThreadGroup.
Just look at them as collection of threads with "group methods". Java API Doc offers more explanation on ThreadGroups, however you are not required to know them for SCJP.
5. Why do we create Demon ThreadGroup? ( may be this is related to the answer of question
#2 because if we can�t have both type of threads in simple ThreadGroup then we may need to create demon ThreadGroup. Just guessing.)
You can have a ThreadGroup with both daemon and user threads. If you want to mark all the threads in a ThreadGroup as daemon, then you can use ThreadGroup.setDaemon(true);.
The documentation says A daemon thread group is automatically destroyed when its last thread is stopped or its last thread group is destroyed.. I have to confess I have never used them, and I don't know if there is any compelling reason to use them.
6. Why does it contain both types of thread ? if simple ThreadGroup can�t have demon threads.
See answer to question 5. Perhaps it was a design decision to allow both non-daemon and daemon threads to belong to the same group. After all, it is just about grouping of threads, nothing more!
Hope this helps. Again, you are NOT REQUIRED TO KNOW ABOUT THREAD GROUPS FOR SCJP EXAM.
Ajith
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Vivek,
I am closing this topic just as it might attract unwarranted importance. Since it is not a part of SCJP objectives, I don't want people to worry too much about ThreadGroups.
Ajith
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic