org.codehaus.gpars

groovyx.gpars.util
[Java] Class EnhancedRWLock

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

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 }*

Authors:
Vaclav Pech Date: Feb 18, 2009


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
java.util.concurrent.locks.ReentrantReadWriteLock#toString(), java.util.concurrent.locks.ReentrantReadWriteLock#getQueueLength(), java.util.concurrent.locks.ReentrantReadWriteLock#getWaitQueueLength(java.util.concurrent.locks.Condition), java.util.concurrent.locks.ReentrantReadWriteLock#hasQueuedThread(java.lang.Thread), java.util.concurrent.locks.ReentrantReadWriteLock#hasQueuedThreads(), java.util.concurrent.locks.ReentrantReadWriteLock#hasWaiters(java.util.concurrent.locks.Condition), java.util.concurrent.locks.ReentrantReadWriteLock#isFair(), java.util.concurrent.locks.ReentrantReadWriteLock#readLock(), java.util.concurrent.locks.ReentrantReadWriteLock#readLock(), java.util.concurrent.locks.ReentrantReadWriteLock#writeLock(), java.util.concurrent.locks.ReentrantReadWriteLock#writeLock(), java.util.concurrent.locks.ReentrantReadWriteLock#getReadHoldCount(), java.util.concurrent.locks.ReentrantReadWriteLock#getReadLockCount(), java.util.concurrent.locks.ReentrantReadWriteLock#getWriteHoldCount(), java.util.concurrent.locks.ReentrantReadWriteLock#isWriteLocked(), java.util.concurrent.locks.ReentrantReadWriteLock#isWriteLockedByCurrentThread(), java.util.concurrent.locks.ReentrantReadWriteLock#wait(long), java.util.concurrent.locks.ReentrantReadWriteLock#wait(), java.util.concurrent.locks.ReentrantReadWriteLock#wait(long, int), java.util.concurrent.locks.ReentrantReadWriteLock#equals(java.lang.Object), java.util.concurrent.locks.ReentrantReadWriteLock#hashCode(), java.util.concurrent.locks.ReentrantReadWriteLock#getClass(), java.util.concurrent.locks.ReentrantReadWriteLock#notify(), java.util.concurrent.locks.ReentrantReadWriteLock#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

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–2010 Václav Pech. All Rights Reserved.