Public class cubbyhole {
PRIVATE INT CONTENTS;
Private boolean available = false;
Public synchronized int GET (INT whO) {
...
}
Public Synchronized Void Put (int who, int value) {
...
}
}
The Method Declarations for Both
Put and
Get Contain THE
SYNCHRONIZED Keyword.
Whenever control enters a synchronized method, the thread that called the method locks the object whose method has been called. Other threads can not call a synchronized method on the same object until the object is unlocked.