multithreading - Does the runnable class go out of scope when a java thread ends? -


if create object implements runnable, , start thread it...

arraylist<thread> threadlist = new arraylist<thread>(); {   mergethread mmt = new mergethread();   thread t = new thread(mmt);   threadlist.add(mmt);   t.start(); }  t.join(); thread t = threadlist.get(0); 

at point mmt guaranteed exist or have gone away if garbage collection got it.

what asking if thread object holds on runnable class after thread has ended.

edit: there's mistake in above should threadlist.add(t);

from source of thread class:

/**  * method called system give thread  * chance clean before exits.  */ private void exit() { if (group != null) {     group.remove(this);     group = null; } /* aggressively null out reference fields: see bug 4006245 */ target = null; /* speed release of of these resources */     threadlocals = null;     inheritablethreadlocals = null;     inheritedaccesscontrolcontext = null;     blocker = null;     uncaughtexceptionhandler = null; } 

so system calls thread#exit() , reference target (which runnable thread running) released.

there bug report #4006245 on bugs.sun.com refers clearing target reference.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -