• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between current thread and this thread??

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic