public class Semaphore{ private int s = 0; public Semaphore(int i){ initS(i); } public synchronized void initS(int i){ s = i; } public synchronized void waitS(){ while (s == 0) { try { wait(); } catch (InterruptedException e) { } } s = s - 1; notifyAll(); } public synchronized void signalS(){ s = s + 1; if ( s == 1) notifyAll(); } }