• 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

Thread object GC eligible?

 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Source of the question is here
Questionn number is 69.



As per the site answer is false.

Should not the objecct be eligible for gc? .
Can anyone explain ?
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think, that object is not eligible for GC, It can do any other thinks after the particular thread has been executed. Waiting for others reply...
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An object is garbage collected when no references point to it. Logically, even when the run() method of a thread does complete its execution, it still has the original reference variable pointing to it. Therefore, it is not eligible for GC.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only thing, we can't do on that, calling the start() method again, then ThreadStateException will throw to console.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that the question's language is not clear. When the question says

The object reference by th is not accessable any more


Its not clear what accessible hear means. To me accessible means there is no reference to an object. In that case it IS eligible for GC...
 
author
Posts: 23951
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
I think the unclear part is here....

th.start() causes the thread to start running and eventually complete its execution.



Is it saying that the start() method complets its execution? Or is it saying that the run() method in the new thread completes it execution?

If it is the first, then the thead object is still accessible from the new newly created thread (even though it is not accessible using th). If it is the second, then it is truely not accessible, and hence, eligible for gc.


Henry
reply
    Bookmark Topic Watch Topic
  • New Topic