+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1added Tutorial examples5a5a002

master
592 B25 linesraw
1//http://tutorials.jenkov.com/java-concurrency/nested-monitor-lockout.html
2public class NestedMon {
3  protected Object monitorObject = new Object();
4  protected boolean isLocked = false;
5
6  public void lock() throws InterruptedException{
7    synchronized(this){
8      while(isLocked){
9        synchronized(this.monitorObject){
10            this.monitorObject.wait();
11        }
12      }
13      isLocked = true;
14    }
15  }
16
17  public void unlock(){
18    synchronized(this){
19      this.isLocked = false;
20      synchronized(this.monitorObject){
21        this.monitorObject.notify();
22      }
23    }
24  }
25}