Block and wait : Wait Notify « Thread « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Thread » Wait Notify 
7.8.2.Block and wait
A running thread may enter a waiting state by a wait(), sleep(), or join() call.

A running thread may enter a waiting state because it can't acquire the lock for synchronized block of code.

wait(), notify(), and notifyAll() must be called from within a synchronized context! 

Class     Method                              Type         Needs                          

Object    try wait(optional timeoutcatch    instance     synchronized, 

Object    notify()                            instance     synchronized                   

Object    notifyAll()                         instance     synchronized                   


Main points to remember about wait():

The calling thread gives up the CPU.
The calling thread gives up the lock.
The calling thread goes into the monitor's waiting pool.

The thread that was notified must reacquire the monitor's lock before it can proceed.
7.8.Wait Notify
7.8.1.Wait and Notify
7.8.2.Block and wait
7.8.3.Both wait() and notify() must be called in synchronized code.
7.8.4.Using Wait() and Notify() to Control Access to a Shared Resource
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.