aspose file tools
The moose likes Threads and Synchronization and the fly likes Thread.currentThread();  and  this(); Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Thread.currentThread();  and  this();" Watch "Thread.currentThread();  and  this();" New topic
Author

Thread.currentThread(); and this();

subhadeep chakraborty
Ranch Hand

Joined: Jul 29, 2006
Posts: 67
Hi,
I am unable to understand the difference between Thread.currentThread() and this(). I have gone through books but i am unable to understand. Any help is appreciated.
Thanks in advance.
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
Thread.currentThread()
Returns a reference to the currently executing thread.

this()
Returns a reference to the currently executing object.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Originally posted by Ahmed Yehia:

this()
Returns a reference to the currently executing object.

Well this() refers to the zero-argument constructor of the class where the code is written and it should only appear in a constructor of the same class and also the first statement of the constructor!
However, i think the poster was referring to just the keyword "this"
Yeah, indeed this refers to the instance of the class on which the currently executing method is called. Of course it can not be used inside a static method or block.

Thread.currentThread() and this will refer to the same object if you are inside a non-static method of the currently executing thread.


apigee, a better way to API!
subhadeep chakraborty
Ranch Hand

Joined: Jul 29, 2006
Posts: 67
You got my question right. Thanks for the correction. My book says with ... (Thread.currentThread() != this) we can test if it is my thread or some arbitrary thread executing my code.. Can you explain this to me .
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Thread.currentThread(); and this();
 
Similar Threads
Constructor calling
How to get the servlet's requesting page ?
priorityQuery problem
explanation needed.
Theta Join