aspose file tools*
The moose likes Threads and Synchronization and the fly likes Difference between current thread and this thread?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Difference between current thread and this thread??" Watch "Difference between current thread and this thread??" New topic
Author

Difference between current thread and this thread??

Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Hello,

I am in reference to the javadoc API for the class java.lang.Thread.

I read from the javadoc that the interrupted method tests whether the current thread has been interrupted and that isInterrupted tests whether this thread has been interrupted.

Can anyone please tell me what the difference is between the current thread and this thread?

Thanks in advance,

Julien.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1760
    
    7

The interrupted() method is declared as a static method, so calling this method will always return and clear the interrupted status of the current thread, which may be one of any number of threads used by an application.

The isInterrupted() method, on the other hand, is an instance() method, so it will return the interrupted status of the thread instance on which the method was invoked, which may or may not be the same thread as the current thread.
Also, in contrast to the interrupted() method, the isInterrupted() method will never clear the interrupted status.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Julien Martin
Ranch Hand

Joined: Apr 24, 2004
Posts: 384
Thanks a lot for your reply,
Still I don't understand what the current thread is since there may be multiple threads executing at the same time... Or to put it otherwise, what would be the point of calling a method on "one of any number of threads used by an application."?
Julien.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1760
    
    7

Originally posted by Julien Martin:
Thanks a lot for your reply,
Still I don't understand what the current thread is since there may be multiple threads executing at the same time.
Julien.


The thread scheduler will only ever allow one runnable thread to run at a time, and that thread is referred to as the current thread.

Edit: Maybe you should have a look at Sun's tutorial on concurrency.
[ August 18, 2008: Message edited by: Jelle Klap ]
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Julien:
Still I don't understand what the current thread is since there may be multiple threads executing at the same time...


Current thread is the thread that has executed the code, calling
Thread.currentThread().

Jelle:
The thread scheduler will only ever allow one runnable thread to run at a time, and that thread is referred to as the current thread.


Yeah, true for system with a single processor but on multi-processor systems, this assumption will fall apart.


apigee, a better way to API!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference between current thread and this thread??