1 package org.jacorb.trading.util; 2 3 8 public class Semaphore { 9 private int count; 10 11 15 public Semaphore() { 16 count = 1; 17 } 18 19 24 public Semaphore(int start_value){ 25 count = start_value; 26 } 27 28 32 public synchronized void P() { 33 while (count == 0){ 34 try{ 35 wait(); 36 } catch (InterruptedException e){ 37 } 38 } 39 count = 0; 40 } 41 42 46 public synchronized void V() { 47 count = 1; 48 notifyAll(); 49 } 50 } 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | Popular Tags |