File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Dan's Exam Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from Dan Watch "Question from Dan New topic
Author

Question from Dan's Exam

Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522

The boolean value false will be returned if 'Thread.interrupted' or 'Thread.isInterrupted' is invoked after the InterruptedException has been thrown.

why this statement is TRUE!!!? isn't it suppose that calling 'Thread.interrupted()' return the state of the thread?
my second question is, why calling 'isInterrupted()' doesn't cause a compile error... i mean isn't this method is supposed to return a boolean value? shouldn't it be called like : 'boolean b = isInterrupted()'?


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270

why this statement is TRUE!!!? isn't it suppose that calling 'Thread.interrupted()' return the state of the thread?

When InterruptedException is thrown, the interuppted status of a thread is cleared. This is why interrupted() and isInterrupted() return false.
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522

When InterruptedException is thrown, the interuppted status of a thread is cleared. This is why interrupted() and isInterrupted() return false.

yes, i noticed that... but my question is why? if it is cleared automatically then we don't ever need to use interrrupted() to clear it, right?
what about my second question?
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Please read carefully Thread.interrupt
We can use isInterrupted() or interrupted() to test the interrupted status of thread that is performing a lengthy task to know if other thread ordered this thread to stop its lengthy job.
If the thread is waiting, joined, or sleeping the exception handler will execute if other thread interrupted it in that state. Then the thread can abandon its task. In that case we already know that thread was interrupted. Thus there is no need of checking with such methods.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Dan's Exam