Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Threads and Garbage Collection

 
 
Andrew Mallinson
Guest
Posts: n/a
 
      01-30-2004
Hey

Ive currently got several threads running in my program that collect data on
how the rest of the program is performing. I just want to make sure that
once these results collection threads have finished ie. got to the end of
their run() method - that it will always still be possible to call their
other methods to access the data.

That is the theads wont be garbage collected until all references to them
within the program are gone.

Also as a side note - is it possible to restart a thread by calling <thread
object name>.start(); - it didnt seem so when I tried it but this was only a
brief test and no error was generated.

Thanks in advance for your help
Regards
Andrew Mallinson


 
Reply With Quote
 
 
 
 
BarryNL
Guest
Posts: n/a
 
      01-30-2004
Andrew Mallinson wrote:
> Hey
>
> Ive currently got several threads running in my program that collect data on
> how the rest of the program is performing. I just want to make sure that
> once these results collection threads have finished ie. got to the end of
> their run() method - that it will always still be possible to call their
> other methods to access the data.
>
> That is the theads wont be garbage collected until all references to them
> within the program are gone.


The objects *won't* be GC'd until all references to them are gone. It
doesn't matter if they're active objects or not, it's the references
that matter.

> Also as a side note - is it possible to restart a thread by calling <thread
> object name>.start(); - it didnt seem so when I tried it but this was only a
> brief test and no error was generated.


Runnable myRunner = new Runnable() {
public void run() {
// do stuff
}
};
Thread myThread = new Thread(myRunner).start();
// do more stuff
if(!myThread.isAlive()) { // has thread finished?
myThread = new Thread(myRunner).start();
}

.... is this what you mean? Not restarting a thread, but does start a new
thread using the same original Runnable object - which is basically the
same thing.

>
> Thanks in advance for your help
> Regards
> Andrew Mallinson

 
Reply With Quote
 
 
 
 
Andrew Mallinson
Guest
Posts: n/a
 
      01-30-2004
> > Also as a side note - is it possible to restart a thread by calling
<thread
> > object name>.start(); - it didnt seem so when I tried it but this was

only a
> > brief test and no error was generated.

>
> Runnable myRunner = new Runnable() {
> public void run() {
> // do stuff
> }
> };
> Thread myThread = new Thread(myRunner).start();
> // do more stuff
> if(!myThread.isAlive()) { // has thread finished?
> myThread = new Thread(myRunner).start();
> }
>
> ... is this what you mean? Not restarting a thread, but does start a new
> thread using the same original Runnable object - which is basically the
> same thing.


Yes it is - thanks for your response
its the same object's run method which is restarting (which is what i
wanted) but using a new thread. - so the actual thread isnt restarted.



 
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
Garbage Collection and Threads Shirish Rai Java 3 06-09-2004 04:56 PM
aspnet_wp.exe garbage collection threads utilization Kevin Jackson ASP .Net 1 05-28-2004 06:41 AM



Advertisments