aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes synchronization - cannot wake a sleeping thread? 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 "synchronization - cannot wake a sleeping thread?" Watch "synchronization - cannot wake a sleeping thread?" New topic
Author

synchronization - cannot wake a sleeping thread?

Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
'notify' will make runnable a waiting thread, but a sleeping thread will always sleep it's time?
There is no method to wake a sleeping thread?

thank you


Nigel
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Never mind. It's late. I'm going to bed now


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
Wouter Oet wrote:Never mind. It's late. I'm going to bed now


Good plan! I think I should also - think with new head tomorrow!
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
Nigel Shrin wrote:'notify' will make runnable a waiting thread, but a sleeping thread will always sleep it's time?
There is no method to wake a sleeping thread?

thank you


Ah - might have found the answer:
you can use an interrupt(), but have to handle/declare an interrupt exception

Is that right?!

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

notify() and notifyAll() methods will notify the Threads, which are waiting for execution, in the pool. I think it's correct thet we can call interrupt() method to interrupt that sleeping thread. But don't have any example coding!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Abimaran Kugathasan wrote:notify() and notifyAll() methods will notify the Threads, which are waiting for execution, in the pool. I think it's correct thet we can call interrupt() method to interrupt that sleeping thread. But don't have any example coding!

Waiting and sleeping are two different things. notify and notifyAll won't wake up a sleeping thread. Only the interrupt method can be used to wake a sleeping thread...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Yea! Thanks Ankit!
Nigel Shrin
Ranch Hand

Joined: May 18, 2009
Posts: 140
thank you Abimaran & Ankit for the clarification - much appreciated
 
Consider Paul's rocket mass heater.
 
subject: synchronization - cannot wake a sleeping thread?