All pastes #840084 Raw Edit

Vermischtes

public java v1 · immutable
#840084 ·published 2007-12-31 13:47 UTC
rendered paste body
/** * Semaphore.java * * A basic counting semaphore using Java synchronization. * */public final class Semaphore{   private int count;   public Semaphore() {      count = 0;   }   public Semaphore(int value) {      count = value;   }   public synchronized void P() {      while (count <= 0) {         System.out.println("Thread " + Thread.currentThread().getName() +" waits in P-Operation!");         try { wait();         } catch (InterruptedException e) {				  Thread.currentThread().interrupt();				  break;		   }      }      count--;   }   public synchronized void V() {      ++count;      notify();   }	public int getCounter() {		return count;	}}