File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Demon ThreadGroup/ThreadGroup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

Demon ThreadGroup/ThreadGroup

Vivek Shrivastava
Ranch Hand

Joined: Jun 03, 2000
Posts: 277
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

Joined: Jun 03, 2000
Posts: 277
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).]
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Demon ThreadGroup/ThreadGroup
 
Similar Threads
Help Please
linux radius server
Thread Group
Scheduling Tests in Jmeter
Need Help