• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Threads and GC

 
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a thread which has a run method like this


And this thread object is instantiated and started in a local method



Assuming the startThread method is called in some other method, what will happen to the Thread object 'tObj' after the end of execution of startThread method? Will 'tObj' thread continue to execute or could it be garbage collected by the JVM?

Thanks
Sudharsan
[ June 08, 2004: Message edited by: Sudharsan G'rajan ]
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It will continue to execute.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh!
Thanks Jose!

-Sudharsan
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The object still keeps running until the object is not reached by the any live reference.

GC of java uses various techniques such as mark and sweep/ refernence counting algorithms to check for the active references. in case the object is not reached by the live refernces object will Garbage collected.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vinay prasad:
The object still keeps running until the object is not reached by the any live reference.



Hi Vinay,

Welcome to JavaRanch!

I wanted to point out that as long as a Thread is running, it will be referenced by its ThreadGroup, and as long as a ThreadGroup contains at least one running thread it, in turn, is referenced by its parent ThreadGroup; therefore, Jose is quite correct in stating that the Thread will continue to run forever (until, of course, something happens to make it stop.) The important point is that under no circumstances will the GC collect a running Thread; it's designed that way quite deliberately.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest! That explains it well.
 
What is that? Is that a mongol hoarde? Can we fend them off with this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic