1 22 package org.jboss.util; 23 24 30 public class WaitSemaphore 31 extends Semaphore 32 implements WaitSync 33 { 34 private final static int MAX_USERS_ALLOWED = 1; 36 37 private int m_waiters; 39 40 42 public WaitSemaphore() 44 { 45 super(MAX_USERS_ALLOWED); 46 } 47 48 public void doWait() throws InterruptedException 50 { 51 synchronized (this) 52 { 53 release(); 54 ++m_waiters; 55 waitImpl(this); 56 --m_waiters; 57 acquire(); 58 } 59 } 60 61 public void doNotify() throws InterruptedException 62 { 63 synchronized (this) 64 { 65 if (getWaiters() > 0) 66 { 67 acquire(); 68 notify(); 69 release(); 70 } 71 } 72 } 73 74 public int getWaiters() 75 { 76 synchronized (this) 77 { 78 return m_waiters; 79 } 80 } 81 82 public String toString() 84 { 85 return super.toString() + " - " + m_waiters; 86 } 87 88 90 92 94 } 96 | Popular Tags |