This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Main thread again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Main thread again" Watch "Main thread again" New topic
Author

Main thread again

vadiraj vd
Ranch Hand

Joined: Dec 15, 2000
Posts: 68
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

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
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Main thread again