Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Garbage Collection and Threads (http://www.velocityreviews.com/forums/t134208-garbage-collection-and-threads.html)

Shirish Rai 06-09-2004 01:45 AM

Garbage Collection and Threads
 
I have a class, say A which is runnable. When A is created it creates one
or more threads. Thus each of these threads have a reference to the
instance of A. Therefore when the client that created A is done using it,
the instance of A cannot be garbage collected.

Is there any way to notify the threads to exit when the thread that
created A is done using it.

Thanks.

Shirish.

Skippy 06-09-2004 09:06 AM

Re: Garbage Collection and Threads
 

> I have a class, say A which is runnable. When A is created it creates one
> or more threads. Thus each of these threads have a reference to the
> instance of A.


Only if you keep a reference floating around. If not, there is no reference
kept anywhere and they will be garbage-collected some time later.



Chris Smith 06-09-2004 04:55 PM

Re: Garbage Collection and Threads
 
Shirish Rai wrote:
> I have a class, say A which is runnable. When A is created it creates one
> or more threads. Thus each of these threads have a reference to the
> instance of A. Therefore when the client that created A is done using it,
> the instance of A cannot be garbage collected.
>
> Is there any way to notify the threads to exit when the thread that
> created A is done using it.


You'll have to take some explicit action at the end of the client that
creates A. That action could involve setting a boolean flag inside A or
interrupting the threads that are running A's code.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Chris Smith 06-09-2004 04:56 PM

Re: Garbage Collection and Threads
 
Skippy wrote:
> > I have a class, say A which is runnable. When A is created it creates one
> > or more threads. Thus each of these threads have a reference to the
> > instance of A.

>
> Only if you keep a reference floating around. If not, there is no reference
> kept anywhere and they will be garbage-collected some time later.


It seems clear that in Shirish's case, the threads are created to run
the instance of A in the first place, so yes they would reference it.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


All times are GMT. The time now is 12:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.