Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Exiting threads

Thread view: 
Ouabaine - 09 Mar 2008 09:52 GMT
Hello all,

In my game, I want to display an animation when I am loading the data
(sounds and graphics). I plan to do this with another thread.
My question : is the thread exited (thread killed, all the resources
cleared) when you exit from the run() method? Or do I have to call a
specific function to clean it?

Thanks for your answers.

Francois
Chris - 09 Mar 2008 21:00 GMT
> Hello all,
>
[quoted text clipped - 7 lines]
>
> Francois

When the run() method exits, the thread is dead and no longer consumes
thread-related resources. The thread object itself, though, may persist
if you still have a reference to it.

For example:

MyThread thread = new MyThread();
thread.start();

// Do other stuff here.
// Thread runs on its own, eventually dies.

// At this point, if the thread variable still points
// to an instance of MyThread, then it and everything it contains
// is still in memory.

// Do this:

thread = null;

// to make it eligible for garbage collection
Lew - 09 Mar 2008 22:35 GMT
> When the run() method exits, the thread is dead and no longer consumes
> thread-related resources. The thread object itself, though, may persist
[quoted text clipped - 15 lines]
>
> thread = null;

Or better yet, just have the variable 'thread' pass out of scope.

Typical use:

 public static void main( String [] args )
 {
   Runnable r = factory.createBasedOn( args );
   Thread t = new Thread( r );
   t.start();
 }

't' goes out of scope after main() returns, so the variable reference
vanishes, enabling GC for the Thread object when it's finished.

This is idiomatically emphasized with

 public static void main( String [] args )
 {
   Runnable r = factory.createBasedOn( args );
   new Thread( r ).start();
 }

Signature

Lew

Ouabaine - 10 Mar 2008 08:13 GMT
Thanks to you both.

Francois


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.