File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Main thread again

 
vadiraj vd
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic