• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Thread Doubt

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.

1. True
2. False

Ans: 2

Doubt: WHY? in this case there is no use of a dead thread and as mentioned "The object reference by th is not accessable any more", so why it will not be garbage collected?


pls help
regards,
gitesh
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gitesh Ramchandani:

Doubt: WHY? in this case there is no use of a dead thread and as mentioned "The object reference by th is not accessable any more", so why it will not be garbage collected?




Cause and Effect.... Is the question saying that you deferenced the variable? Or is the question saying that the variable will be automatically dereferenced when the thread completes?

This is why it would help if you Quote Your Sources. It may provide more context.

Henry
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
source:

AngelFire/Abhilash Q-69
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer is Simple. Because GC in NOT GUARANTEED. It might run but not sweep any eligible object. Hence, its falls to say any un-referenced object will ever be GCed ,when GC runs next time.
[ August 29, 2007: Message edited by: ajay futuro ]
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ajay futuro:
Answer is Simple. Because GC in NOT GUARANTEED. It might run but not sweep any eligible object. Hence, its falls to say any un-referenced object will ever be GCed ,when GC runs next time.

[ August 29, 2007: Message edited by: ajay futuro ]



Ok, but if it would have asked, like..will the reference th be GC, then would the answer be true?

Gitesh
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

As per my understanding, once a thread completes its run() method, it moves to dead state. i.e it can not be thread of execution again. In trying to invoke start() method again on that reference, we will have an exception in place. But thread object itself is not nullified. The object is still on heap and has a valid reference.In fact, we can still invoke any other methods defined in our thread object except start(). Now since the object is having a reference, it is basically not eligible for GC. Correct me if I'm wrong. Thanks in advance.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chandra Kota:
Hello All,

As per my understanding, once a thread completes its run() method, it moves to dead state. i.e it can not be thread of execution again. In trying to invoke start() method again on that reference, we will have an exception in place. But thread object itself is not nullified. The object is still on heap and has a valid reference.In fact, we can still invoke any other methods defined in our thread object except start(). Now since the object is having a reference, it is basically not eligible for GC. Correct me if I'm wrong. Thanks in advance.




Perfect!
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chandra
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic