Top Description Fields Constructors Methods
net.sf.ehcache.concurrent

public Class ReadWriteLockSync

extends Object
implements Sync
Class Inheritance
All Implemented Interfaces
net.sf.ehcache.concurrent.Sync
Imports
java.util.concurrent.locks.ReentrantReadWriteLock, .Lock, .ReadWriteLock, java.util.concurrent.TimeUnit

A simple ReadWriteLock synchronizer.
Author
Alex Snaps

Field Summary

Modifier and TypeField and Description
private final ReentrantReadWriteLock

Constructor Summary

AccessConstructor and Description
public
ReadWriteLockSync()

default constructor.

public

Method Summary

Modifier and TypeMethod and Description
private Lock
getLock(final LockType type)

public ReadWriteLock

Returns:

the backing ReadWriteLock
getReadWriteLock
()

Gets the ReadWriteLock backing this sync.

public boolean
isHeldByCurrentThread(LockType
the lock type to test
type
)

Implements net.sf.ehcache.concurrent.Sync.isHeldByCurrentThread.

Returns true is this is lock is held at given level by the current thread.
public void
lock(final LockType
the lock type to acquire
type
)

Implements net.sf.ehcache.concurrent.Sync.lock.

Acquire lock of LockType.READ or WRITE
public boolean
tryLock(final LockType
the lock type to acquire
type
,
final long
timeout
msec
)

Implements net.sf.ehcache.concurrent.Sync.tryLock.

Tries to acquire a LockType.READ or WRITE for a certain period
public void
unlock(final LockType
the lock type to acquire
type
)

Implements net.sf.ehcache.concurrent.Sync.unlock.

Releases the lock held by the current Thread.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rrwlback to summary
private final ReentrantReadWriteLock rrwl

Constructor Detail

ReadWriteLockSyncback to summary
public ReadWriteLockSync()

default constructor.

ReadWriteLockSyncback to summary
public ReadWriteLockSync(ReentrantReadWriteLock lock)

Constructor.

Method Detail

getLockback to summary
private Lock getLock(final LockType type)
getReadWriteLockback to summary
public ReadWriteLock getReadWriteLock()

Gets the ReadWriteLock backing this sync.

Returns:ReadWriteLock

the backing ReadWriteLock

isHeldByCurrentThreadback to summary
public boolean isHeldByCurrentThread(LockType type)

Implements net.sf.ehcache.concurrent.Sync.isHeldByCurrentThread.

Doc from net.sf.ehcache.concurrent.Sync.isHeldByCurrentThread.

Returns true is this is lock is held at given level by the current thread.

Parameters
type:LockType

the lock type to test

Returns:boolean

true if the lock is held

lockback to summary
public void lock(final LockType type)

Implements net.sf.ehcache.concurrent.Sync.lock.

Doc from net.sf.ehcache.concurrent.Sync.lock.

Acquire lock of LockType.READ or WRITE

Parameters
type:LockType

the lock type to acquire

tryLockback to summary
public boolean tryLock(final LockType type, final long msec) throws InterruptedException

Implements net.sf.ehcache.concurrent.Sync.tryLock.

Doc from net.sf.ehcache.concurrent.Sync.tryLock.

Tries to acquire a LockType.READ or WRITE for a certain period

Parameters
type:LockType

the lock type to acquire

msec:long

timeout

Returns:boolean

true if the lock got acquired, false otherwise

Exceptions
InterruptedException:
Should the thread be interrupted
unlockback to summary
public void unlock(final LockType type)

Implements net.sf.ehcache.concurrent.Sync.unlock.

Doc from net.sf.ehcache.concurrent.Sync.unlock.

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

Parameters
type:LockType

the lock type to acquire