Extends Semaphore with a handy withSemaphore(Closure) method to safely acquire and release the Semaphore for the passed-in closure. Use: def extendedSemaphore = new ExtendedSemaphore() extendedSemaphore.withSemaphore() {* //semaphore acquired here }*
Modifiers | Name | Description |
---|---|---|
private static long |
serialVersionUID |
Constructor and description |
---|
EnhancedSemaphore
(int permits) Creates a new EnhancedSemaphore, delegating to the Semaphore class constructor. |
Type | Name and description |
---|---|
void |
withSemaphore(groovy.lang.Closure cl) Performs the passed-in closure with the Semaphore acquired and releases the Semaphore automatically after the closure finishes. |
Methods inherited from class | Name |
---|---|
class java.util.concurrent.Semaphore |
java.util.concurrent.Semaphore#toString(), java.util.concurrent.Semaphore#getQueueLength(), java.util.concurrent.Semaphore#hasQueuedThreads(), java.util.concurrent.Semaphore#isFair(), java.util.concurrent.Semaphore#release(int), java.util.concurrent.Semaphore#release(), java.util.concurrent.Semaphore#acquire(), java.util.concurrent.Semaphore#acquire(int), java.util.concurrent.Semaphore#tryAcquire(int, long, java.util.concurrent.TimeUnit), java.util.concurrent.Semaphore#tryAcquire(int), java.util.concurrent.Semaphore#tryAcquire(long, java.util.concurrent.TimeUnit), java.util.concurrent.Semaphore#tryAcquire(), java.util.concurrent.Semaphore#acquireUninterruptibly(), java.util.concurrent.Semaphore#acquireUninterruptibly(int), java.util.concurrent.Semaphore#availablePermits(), java.util.concurrent.Semaphore#drainPermits(), java.util.concurrent.Semaphore#wait(), java.util.concurrent.Semaphore#wait(long, int), java.util.concurrent.Semaphore#wait(long), java.util.concurrent.Semaphore#equals(java.lang.Object), java.util.concurrent.Semaphore#hashCode(), java.util.concurrent.Semaphore#getClass(), java.util.concurrent.Semaphore#notify(), java.util.concurrent.Semaphore#notifyAll() |
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Creates a new EnhancedSemaphore, delegating to the Semaphore class constructor.
permits
- Maximum number of concurrently accepted threads.Performs the passed-in closure with the Semaphore acquired and releases the Semaphore automatically after the closure finishes.
cl
- The closure to perform with the Semaphore acquiredCopyright © 2008–2014 Václav Pech. All Rights Reserved.