Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Garbage Collection and Threads

Reply
Thread Tools

Garbage Collection and Threads

 
 
Shirish Rai
Guest
Posts: n/a
 
      06-09-2004
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.
 
Reply With Quote
 
 
 
 
Skippy
Guest
Posts: n/a
 
      06-09-2004

> 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.


 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      06-09-2004
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
 
Reply With Quote
 
Chris Smith
Guest
Posts: n/a
 
      06-09-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads preventing garbage collection? Brian Candler Ruby 11 09-18-2008 03:53 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
Garbage Collection of Threads WonderboyFromMars@googlemail.com Java 8 11-17-2005 05:19 PM
aspnet_wp.exe garbage collection threads utilization Kevin Jackson ASP .Net 1 05-28-2004 06:41 AM
Threads and Garbage Collection Andrew Mallinson Java 2 01-30-2004 03:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57