public class Resource { private boolean available; public Resource() { this.available = true; } public synchronized void acquire() { while (!this.available) { try { this.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } this.available = false; } public synchronized void release() { this.available = true; this.notifyAll(); } }