Groovy Documentation

gpars.util
Class EnhancedRWLock

java.lang.Object
  java.util.concurrent.locks.ReentrantReadWriteLock
      gpars.util.EnhancedRWLock

class EnhancedRWLock
extends ReentrantReadWriteLock

Extends ReentrantReadWriteLock with handy withReadLock(Closure) and withWriteLock(Closure) methods to safely lock and unlock the lock for the passed-in closure. Use: def extendedLock = new ExtendedRWLock() extendedLock.withReadLock() {* //read lock locked here }*

author:
Vaclav Pech Date: Feb 18, 2009


Constructor Summary
EnhancedRWLock()

EnhancedRWLock(boolean fair)

 
Method Summary
void withReadLock(groovy.lang.Closure cl)

Performs the passed-in closure with the read lock locked and unlocks the read lock automatically after the closure finishes.

void withWriteLock(groovy.lang.Closure cl)

Performs the passed-in closure with the write lock locked and unlocks the write lock automatically after the closure finishes.

 
Methods inherited from class ReentrantReadWriteLock
toString, readLock, readLock, writeLock, writeLock, isFair, hasQueuedThreads, hasQueuedThread, getQueueLength, hasWaiters, getWaitQueueLength, getReadLockCount, isWriteLocked, isWriteLockedByCurrentThread, getWriteHoldCount, getReadHoldCount, wait, wait, wait, equals, hashCode, getClass, notify, notifyAll
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

EnhancedRWLock

public EnhancedRWLock()


EnhancedRWLock

public EnhancedRWLock(boolean fair)


 
Method Detail

withReadLock

public void withReadLock(groovy.lang.Closure cl)
Performs the passed-in closure with the read lock locked and unlocks the read lock automatically after the closure finishes.
param:
cl The closure to perform with the read lock held


withWriteLock

public void withWriteLock(groovy.lang.Closure cl)
Performs the passed-in closure with the write lock locked and unlocks the write lock automatically after the closure finishes.
param:
cl The closure to perform with the write lock held


 

Groovy Documentation