com.pelzer.util
Class SafeSemaphore

java.lang.Object
  extended by com.pelzer.util.SafeSemaphore

public class SafeSemaphore
extends Object

A wrapper around the concurrent.Semaphore object, which returns an actual permit object when acquire() is called, which can then be used to release the lock, and has safety finalizers that ensure that an acquired permit will eventually be released during garbage collection if a thread crash or other bug breaks the code before semaphore release.


Nested Class Summary
 class SafeSemaphore.Permit
           
 
Constructor Summary
SafeSemaphore(int initialPermits)
           
 
Method Summary
 SafeSemaphore.Permit acquire()
          Wait until a permit is available, and take one.
 SafeSemaphore.Permit acquireUninterruptibly()
          Same as acquire(), but won't throw an InterruptedException.
 void release(SafeSemaphore.Permit permit)
          Release a permit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SafeSemaphore

public SafeSemaphore(int initialPermits)
Method Detail

acquire

public SafeSemaphore.Permit acquire()
                             throws InterruptedException
Wait until a permit is available, and take one.

Throws:
InterruptedException

acquireUninterruptibly

public SafeSemaphore.Permit acquireUninterruptibly()
Same as acquire(), but won't throw an InterruptedException.


release

public void release(SafeSemaphore.Permit permit)
Release a permit. Really, the same as calling permit.release().



Copyright © 2012. All Rights Reserved.