If I create an object that implements Runnable, and I start a thread with 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 this point is mmt guaranteed to exist or could it have gone away if garbage collection got it.
What I am asking is if the Thread object holds on to the Runnable class after the thread has ended.
edit: there’s a mistake in the above it should say
threadlist.add(t);
From the source of the
Threadclass:So the system calls
Thread#exit()and the reference totarget(which is a runnable the thread is running) is released.There is also a bug report #4006245 on bugs.sun.com that refers to clearing the
targetreference.