Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

finishing a thread  RSS feed

 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a Thread completes whatever it's doing in its run() method, is that Thread object discarded and ready for garbage collection?
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless if a thread is running or not, if the number of references to that object is equal to or greater than 1, then it wont be a candidate for garbage collection.
After a thread returns from its run() method, it does not get destroyed by any means. It's still an object whose methods and attributes can be accessed by other objects.
SAF
 
Paul Keohan
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it only goes away when the JVM is no longer in use for whatever application you're running?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!