public class GCUBEReadWriteLock extends ReentrantReadWriteLock
ReentrantReadWriteLock that allows preemptive acquisition of write locks.
A thread acquires the write lock preemptively (cf. GCUBEReadWriteLock.GCUBEWriteLock.lockPreemptively()) if its actions
preempt those of other threads that synchronise with it (e.g. removal of guarded state).
When the preemptive thread releases the write lock, threads that were waiting for it or will request it in the future
are immediately interrupted, unless the preemptive thread declares its own failure (cf. GCUBEReadWriteLock.GCUBEWriteLock.cancelPreemptive()).
The possibility of lock preemption implies that all locking operations are interruptible in principle.
Accordingly, GCUBEReadWriteLock.GCUBEWriteLock.lock() and GCUBEReadWriteLock.GCUBEReadLock.lock() are deprecated in favour of
GCUBEReadWriteLock.GCUBEWriteLock.lockInterruptibly() and GCUBEReadWriteLock.GCUBEReadLock.lockInterruptibly(). If used, they may throw
a LockPreemptedException.
| Modifier and Type | Class and Description |
|---|---|
static class |
GCUBEReadWriteLock.GCUBEReadLock
An extension of
ReentrantReadWriteLock.WriteLock that supports
preemptive requests and acquisitions. |
static class |
GCUBEReadWriteLock.GCUBEWriteLock
An extension of
ReentrantReadWriteLock.WriteLock that supports
preemptive requests and acquisitions. |
ReentrantReadWriteLock.ReadLock, ReentrantReadWriteLock.WriteLock| Modifier and Type | Field and Description |
|---|---|
protected GCUBELog |
logger
Class logger.
|
protected boolean |
preempted
Indicates completion of preemptive task.
|
protected Thread |
preemptingThread
The thread that performs the preemptive task.
|
| Constructor and Description |
|---|
GCUBEReadWriteLock()
Creates an instance.
|
GCUBEReadWriteLock(boolean fair)
Creates an instance with a given fairness policy.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isPreempted()
Used internally to check whether the lock has been requested preemptively by a thread other
than the current one.
|
GCUBEReadWriteLock.GCUBEReadLock |
readLock() |
void |
setLogger(GCUBELog logger)
Sets the resource's logger.
|
GCUBEReadWriteLock.GCUBEWriteLock |
writeLock() |
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, toStringprotected GCUBELog logger
protected volatile Thread preemptingThread
protected volatile boolean preempted
public GCUBEReadWriteLock()
public GCUBEReadWriteLock(boolean fair)
fair - true if this lock should use a fair ordering policypublic void setLogger(GCUBELog logger)
logger - the logger.public GCUBEReadWriteLock.GCUBEWriteLock writeLock()
writeLock in interface ReadWriteLockwriteLock in class ReentrantReadWriteLockpublic GCUBEReadWriteLock.GCUBEReadLock readLock()
readLock in interface ReadWriteLockreadLock in class ReentrantReadWriteLockprotected boolean isPreempted()
LockPreemptedException - if the lock has been requested preemptively by a thread other
than the current one.Copyright © 2015. All Rights Reserved.