org.codehaus.gpars

groovyx.gpars.util
[Java] Class EnhancedSemaphore

java.lang.Object
  java.util.concurrent.Semaphore
      groovyx.gpars.util.EnhancedSemaphore

public class EnhancedSemaphore
extends java.util.concurrent.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


Field Summary
private static long serialVersionUID

 
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 java.util.concurrent.Semaphore
java.util.concurrent.Semaphore#toString(), java.util.concurrent.Semaphore#acquire(), java.util.concurrent.Semaphore#acquire(int), java.util.concurrent.Semaphore#release(), java.util.concurrent.Semaphore#release(int), java.util.concurrent.Semaphore#getQueueLength(), java.util.concurrent.Semaphore#hasQueuedThreads(), java.util.concurrent.Semaphore#isFair(), java.util.concurrent.Semaphore#tryAcquire(long, java.util.concurrent.TimeUnit), java.util.concurrent.Semaphore#tryAcquire(), java.util.concurrent.Semaphore#tryAcquire(int), java.util.concurrent.Semaphore#tryAcquire(int, long, java.util.concurrent.TimeUnit), java.util.concurrent.Semaphore#acquireUninterruptibly(int), java.util.concurrent.Semaphore#acquireUninterruptibly(), java.util.concurrent.Semaphore#availablePermits(), java.util.concurrent.Semaphore#drainPermits(), java.util.concurrent.Semaphore#wait(long), java.util.concurrent.Semaphore#wait(), java.util.concurrent.Semaphore#wait(long, int), 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()
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), 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()
 

Field Detail

serialVersionUID

private static final long serialVersionUID


 
Constructor Detail

EnhancedSemaphore

public EnhancedSemaphore(int permits)
Creates a new EnhancedSemaphore, delegating to the Semaphore class constructor.
Parameters:
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.
throws:
InterruptedException If the current thread gets interrupted
Parameters:
cl - The closure to perform with the Semaphore acquired


 

Copyright © 2008–2012 Václav Pech. All Rights Reserved.