com.pelzer.util
Class SafeSemaphore
java.lang.Object
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.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SafeSemaphore
public SafeSemaphore(int initialPermits)
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.