ehcache

net.sf.ehcache.concurrent
Class ReadWriteLockSync

java.lang.Object
  extended by net.sf.ehcache.concurrent.ReadWriteLockSync
All Implemented Interfaces:
Sync

public class ReadWriteLockSync
extends Object
implements Sync

A simple ReadWriteLock synchronizer.

Author:
Alex Snaps

Field Summary
 
Fields inherited from interface net.sf.ehcache.concurrent.Sync
ONE_CENTURY, ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK, ONE_YEAR
 
Constructor Summary
ReadWriteLockSync()
          default constructor.
ReadWriteLockSync(ReentrantReadWriteLock lock)
          Constructor.
 
Method Summary
 ReadWriteLock getReadWriteLock()
          Gets the ReadWriteLock backing this sync.
 boolean isHeldByCurrentThread(LockType type)
          Returns true is this is lock is held at given level by the current thread.
 void lock(LockType type)
          Acquire lock of LockType.READ or WRITE
 boolean tryLock(LockType type, long msec)
          Tries to acquire a LockType.READ or WRITE for a certain period
 void unlock(LockType type)
          Releases the lock held by the current Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadWriteLockSync

public ReadWriteLockSync()
default constructor.


ReadWriteLockSync

public ReadWriteLockSync(ReentrantReadWriteLock lock)
Constructor.

Parameters:
lock -
Method Detail

lock

public void lock(LockType type)
Acquire lock of LockType.READ or WRITE

Specified by:
lock in interface Sync
Parameters:
type - the lock type to acquire

tryLock

public boolean tryLock(LockType type,
                       long msec)
                throws InterruptedException
Tries to acquire a LockType.READ or WRITE for a certain period

Specified by:
tryLock in interface Sync
Parameters:
type - the lock type to acquire
msec - timeout
Returns:
true if the lock got acquired, false otherwise
Throws:
InterruptedException - Should the thread be interrupted

unlock

public void unlock(LockType type)
Releases the lock held by the current Thread. In case of a LockType.WRITE, should the lock not be held by the current Thread, nothing happens

Specified by:
unlock in interface Sync
Parameters:
type - the lock type to acquire

getReadWriteLock

public ReadWriteLock getReadWriteLock()
Gets the ReadWriteLock backing this sync.

Returns:
the backing ReadWriteLock

isHeldByCurrentThread

public boolean isHeldByCurrentThread(LockType type)
Returns true is this is lock is held at given level by the current thread.

Specified by:
isHeldByCurrentThread in interface Sync
Parameters:
type - the lock type to test
Returns:
true if the lock is held

ehcache

Copyright 2001-2015, Terracotta, Inc.