public class Semaphore { byte value = 1; public Semaphore(byte init_value) { value = init_value; } public synchronized void down() { while(value==0) { try { wait(); } catch(InterruptedException ex) {} } value--; } public synchronized void up() { value++; notifyAll(); } }