class Semaphore { private int value; public Semaphore(int value) { this.value = value; } synchronized public void acquire() throws InterruptedException { while (this.value <= 0) { wait(); } this.value--; } synchronized public void release() { this.value++; notify(); } }