Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two queries

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question and a query.
question: does yield() hold all locks?
query: in ThreadGroup we can set a ThreadGroup to be of "daemon" type. now, api says that if a ThreadGroup is of "daemon" type then it will be destroyed only when all of it's member threads are finished. My question is what do we mean by "destroy" on ThreadGroup?? Does it mean that the ThreadGroup object becomes eligible for GrabageCollection?
Well, if that is the case then what happens in following code,
ThreadGroup tg = new ThreadGroup();
// code of many threads and their binding
// to the above threadgroup "tg"
// all the member threads are started
tg = null; // now at this point we made tg
// explicitly "null" to make it
// eligible for GC but suppose
// that some member threads are still
// running, then what happens??
hope i am clear in explaining my problem.
regards
maulin
 
Suresh Bansal
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeild() will allow other same priority threads to run.
For daemon threads.
If the program has no more non daemon threads, the system exits and destroys daemon threads in the process. The presence of daemon threads does not stop the program from exting.
I think, that setting threadgroup to null will not destroy the threads in it.
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yield does not release locks.
After a while I have managed to produce this code that shows, I hope, that a daemon threadGroup is only garbage collected when its threads have finished. However a non daemon one it is not garbage collected even then.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jose,
I guess you are right.
And one more thing, instead of writing "threadgroup is destroyed ONLY when all of it's member threads are finished" I should have said "threadgrou is Destroyed when all of its member threads are finished" for Daemon Threadgroups (to be precise as in API).
That makes the same suggestion you made, we can guarantee about destroyal of a daemon ThreadGroup when all of i'ts member threads are finished but we can't be sure the same about the non-daemon threadgroup.
Yeah..it makes sense.
Btw, I am impressed that you could come upwith a code particularly because I know little about those lang.ref package classes so I couldn't have come up with similar example myself.
Thanks!
Maulin.
Maulin.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic