• 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

Two queries

 
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,
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
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic