Hi all, I have doubt in this program. Can somebody explain me what's happenning here? I executed this and getting the output. Thanx in advance. --------- vadiraj The Code : public class MainThreadEqualToNull { public static void main(String a[]) { Thread t = Thread.currentThread(); // obtain the reference of current thread. t = null; // Assign to null System.out.println("this is after main thread is assigned to null"); } }
Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************
Bharatesh H Kakamari
Ranch Hand
Joined: Nov 09, 2000
Posts: 198
posted
0
Thread t = Thread.currentThread(); // obtain the reference of current thread.
In this line you are getting the reference of the current thread object as you have already mentioned
t = null; // Assign to null
You are setting the reference to null not the object , hence the output.
vadiraj vd
Ranch Hand
Joined: Dec 15, 2000
Posts: 68
posted
0
You are setting the reference to null not the object , hence the output.[/B]
Thanks Bharatesh, but when the reference of any thread is asigned to null, we can't able to access that thread and that thread becomes eligible for garbage collection. Thanx again ---vadiraj