This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Unable to understand statement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Unable to understand statement?" Watch "Unable to understand statement?" New topic
Author

Unable to understand statement?

manish ghildiyal
Ranch Hand

Joined: Jan 12, 2013
Posts: 136
Hi,

I got this from Oracle java docs
(http://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html)

Many methods that throw InterruptedException, such as sleep, are designed to cancel their current operation and return immediately when an interrupt is received.


.....so when a thread is in dormant/blocked state(due to invocation of sleep method)
and it is interrupted then sleep method throws InterruptedException....so sleep method either returns as stated above or throws exception...how can
both happen together?

Manish
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18507
    
  40

manish ghildiyal wrote:
I got this from Oracle java docs
(http://docs.oracle.com/javase/tutorial/essential/concurrency/interrupt.html)

Many methods that throw InterruptedException, such as sleep, are designed to cancel their current operation and return immediately when an interrupt is received.


.....so when a thread is in dormant/blocked state(due to invocation of sleep method)
and it is interrupted then sleep method throws InterruptedException....so sleep method either returns as stated above or throws exception...how can
both happen together?



I think you may be too literal in your interpretation. In this case, I think that it is safe to assume that the word "return" does not mean the literal execution of the "return" keyword; it simply means "returning back from the method" -- and that includes throwing an exception.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
manish ghildiyal
Ranch Hand

Joined: Jan 12, 2013
Posts: 136
Hi Henry,

Thanks for clarification.

Manish

 
Don't get me started about those stupid light bulbs.
 
subject: Unable to understand statement?
 
Similar Threads
InterruptedException in multi threading
Why does the method Thread.sleep() declare that it might throw an exception?
why you have to catch InterruptedException
Synchronization practice: why does thread1 rush through loop without pause or reset?
Future.cancel(true)