• 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

Thread methods

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i am not able to understand the following 2 methods of Thread class:
public static boolean interrupted()
public boolean isInterrupted()
i have already gone through APIs for this purpose but it confuses me,especially the term "interrupted status" of the thread.In second method interrupted status is unaffected unlike the first method.Why???
Can some1 pls explain these two methods to me?thanx in advance.
rajashree.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The first method is static and test whether the CURRENTLY running thread is interrupted or not.
The second is an instance method and tests whether the thread instance on which the method is invoked is interrupted or not.
Be aware that there is a difference between a static and an instance method. The static method will be invoked on the thread instance that is currently active, while the instance method may be invoked on any instance of a thread.
Hope that helps
Val
 
rajashree ghatak
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Valentin for ur response.
What am i still confused about is the APIs say,
static boolean interrupted()-The interrupted status of the thread is cleared by this method.In other words, if this method were to be called twice in succession, the second call would return false (unless the current thread were interrupted again, after the first call had cleared its interrupted status and before the second call had examined it).
boolean isInterrupted()-The interrupted status of the thread is unaffected by this method.What is meant by the sentence interrupted status of the thread is cleared?
Can anyone pls explain the meaning of the above definitions of the 2 methods?
rajashree.
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interrupted() checks the status of the thread to see whether it has been interrupted. If it has it retuns true. But before it returns, it sets the status of the thread to false.So any subsequent calls to interrupted()would return false. However if the thread had not been interrupted it just returns a false, without chnaging the status.
But isInterrupted() just returns the current status of the thread without tampering with the status under any condition.
 
rajashree ghatak
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx Sunetra for ur explanation.my doubt has got cleared to a great extent.could u pls explain the meaning of this statement:
static boolean isInterrupted()-if this method were to be called twice in succession, the second call would return false (unless the current thread were interrupted again, after the first call had cleared its interrupted status and before the second call had examined it).

waiting to hear from u,
rajashree.
 
reply
    Bookmark Topic Watch Topic
  • New Topic