Groovy Documentation

gpars.util
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 }*

author:
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
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

EnhancedSemaphore

public EnhancedSemaphore(int permits)
Creates a new EnhancedSemaphore, delegating to the Semaphore class constructor.
param:
permits Maximum number of concurrently accepted threads.


 
Method Detail

withSemaphore

public void withSemaphore(groovy.lang.Closure cl)
Performs the passed-in closure with the Semaphore acquired and releases the Semaphore automatically after the closure finishes.
param:
cl The closure to perform with the Semaphore acquired


 

Groovy Documentation