gpars.util
[Groovy] Class EnhancedSemaphore
java.lang.Object
java.util.concurrent.Semaphore
gpars.util.EnhancedSemaphore
class EnhancedSemaphore
extends Semaphore
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
}*
- Authors:
- Vaclav Pech
Date: Jan 8, 2009
Constructor Summary |
EnhancedSemaphore(int permits)
Creates a new EnhancedSemaphore, delegating to the Semaphore class constructor.
|
Method Summary |
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 Semaphore
|
toString, isFair, hasQueuedThreads, getQueueLength, release, release, tryAcquire, tryAcquire, tryAcquire, tryAcquire, acquire, acquire, acquireUninterruptibly, acquireUninterruptibly, availablePermits, drainPermits, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll |
EnhancedSemaphore
EnhancedSemaphore(int permits)
- Creates a new EnhancedSemaphore, delegating to the Semaphore class constructor.
- Parameters:
permits
- Maximum number of concurrently accepted threads.
withSemaphore
void withSemaphore(groovy.lang.Closure cl)
- Performs the passed-in closure with the Semaphore acquired and releases the Semaphore automatically
after the closure finishes.
- Parameters:
cl
- The closure to perform with the Semaphore acquired
Groovy Documentation