groovyx.gpars.util
Class EnhancedRWLock

java.lang.Object
  extended by java.util.concurrent.locks.ReentrantReadWriteLock
      extended by groovyx.gpars.util.EnhancedRWLock
All Implemented Interfaces:
java.io.Serializable, java.util.concurrent.locks.ReadWriteLock

public class EnhancedRWLock
extends java.util.concurrent.locks.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
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock, java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock
 
Field Summary
private static long serialVersionUID
           
 
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 java.util.concurrent.locks.ReentrantReadWriteLock
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, toString, writeLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
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.

Parameters:
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.

Parameters:
cl - The closure to perform with the write lock held

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