public class ConcurrencyManager extends Object implements Serializable
Purpose: To maintain concurrency for a paticular task. It is a wrappers of a semaphore that allows recursive waits by a single thread.
Responsibilities:
Modifier and Type | Field and Description |
---|---|
protected Thread |
activeThread |
static Hashtable |
deferredLockManagers |
protected int |
depth |
protected boolean |
lockedByMergeManager |
protected int |
numberOfReaders |
protected int |
numberOfWritersWaiting |
protected CacheKey |
ownerCacheKey
Cachkey owner set when ConcurrencyMananger is used within an cachekey on an idenity map
Used to store the owner so that the object involved can be retrieved from the cachekey
|
Constructor and Description |
---|
ConcurrencyManager()
Initialize the newly allocated instance of this class.
|
ConcurrencyManager(CacheKey cacheKey)
Initialize a new ConcurrencyManger, seting depth to zero and setting the
owner cacheKey.
|
Modifier and Type | Method and Description |
---|---|
void |
acquire()
Wait for all threads except the active thread.
|
void |
acquire(boolean forMerge)
Wait for all threads except the active thread.
|
void |
acquireDeferredLock()
Add deferred lock into a hashtable to avoid deadlock
|
boolean |
acquireNoWait()
If the lock is not acquired allready acquire it and return true.
|
boolean |
acquireNoWait(boolean forMerge)
If the lock is not acquired allready acquire it and return true.
|
void |
acquireReadLock()
Wait on any writer.
|
boolean |
acquireReadLockNoWait()
If this is acquired return false otherwise acquire readlock and return true
|
void |
checkReadLock()
Check the lock state, if locked, acquire and release a read lock.
|
Thread |
getActiveThread()
Return the active thread.
|
static DeferredLockManager |
getDeferredLockManager(Thread thread)
Return the deferred lock manager from the thread
|
protected static Hashtable |
getDeferredLockManagers()
Return the deferred lock manager hashtable (thread - DeferredLockManager).
|
int |
getDepth()
Return the current depth of the active thread.
|
int |
getNumberOfReaders()
Number of writer that want the lock.
|
int |
getNumberOfWritersWaiting()
Number of writers that want the lock.
|
CacheKey |
getOwnerCacheKey()
Returns the owner cache key for this concurrency manager
|
boolean |
isAcquired()
Return if a thread has aquire this manager.
|
static boolean |
isBuildObjectOnThreadComplete(Thread thread,
IdentityHashtable recursiveSet)
Check if the deferred locks of a thread are all released
|
boolean |
isLockedByMergeManager()
INTERNAL:
Used byt the refresh process to determine if this concurrency manager is locked by
the merge process.
|
boolean |
isNested()
Return if this manager is within a nested aquire.
|
void |
putDeferredLock(Thread thread,
DeferredLockManager lockManager) |
void |
release()
Decrement the depth for the active thread.
|
void |
releaseDeferredLock()
Release the deferred lock.
|
void |
releaseReadLock()
Decrement the number of readers.
|
static DeferredLockManager |
removeDeferredLockManager(Thread thread)
Remove the deferred lock manager for the thread
|
void |
setActiveThread(Thread activeThread)
Set the active thread.
|
protected void |
setDepth(int depth)
Set the current depth of the active thread.
|
void |
setIsLockedByMergeManager(boolean state)
INTERNAL:
Used by the mergemanager to let the read know not to refresh this object as it is being
loaded by the merge process.
|
protected void |
setNumberOfReaders(int numberOfReaders)
Track the number of readers.
|
protected void |
setNumberOfWritersWaiting(int numberOfWritersWaiting)
Number of writers that want the lock.
|
String |
toString()
Print the nested depth.
|
protected int numberOfReaders
protected int depth
protected int numberOfWritersWaiting
protected transient Thread activeThread
public static Hashtable deferredLockManagers
protected boolean lockedByMergeManager
protected CacheKey ownerCacheKey
public ConcurrencyManager()
public ConcurrencyManager(CacheKey cacheKey)
public void acquire() throws ConcurrencyException
ConcurrencyException
public void acquire(boolean forMerge) throws ConcurrencyException
ConcurrencyException
public boolean acquireNoWait() throws ConcurrencyException
ConcurrencyException
public boolean acquireNoWait(boolean forMerge) throws ConcurrencyException
ConcurrencyException
public void acquireDeferredLock() throws ConcurrencyException
ConcurrencyException
public void checkReadLock() throws ConcurrencyException
ConcurrencyException
public void acquireReadLock() throws ConcurrencyException
ConcurrencyException
public boolean acquireReadLockNoWait()
public Thread getActiveThread()
public static DeferredLockManager getDeferredLockManager(Thread thread)
protected static Hashtable getDeferredLockManagers()
public int getDepth()
public int getNumberOfReaders()
public int getNumberOfWritersWaiting()
public CacheKey getOwnerCacheKey()
public boolean isAcquired()
public boolean isLockedByMergeManager()
public static boolean isBuildObjectOnThreadComplete(Thread thread, IdentityHashtable recursiveSet)
public boolean isNested()
public void putDeferredLock(Thread thread, DeferredLockManager lockManager)
public void release() throws ConcurrencyException
ConcurrencyException
public void releaseDeferredLock() throws ConcurrencyException
ConcurrencyException
public void releaseReadLock() throws ConcurrencyException
ConcurrencyException
public static DeferredLockManager removeDeferredLockManager(Thread thread)
public void setActiveThread(Thread activeThread)
protected void setDepth(int depth)
public void setIsLockedByMergeManager(boolean state)
protected void setNumberOfReaders(int numberOfReaders)
protected void setNumberOfWritersWaiting(int numberOfWritersWaiting)
Copyright © 2023. All rights reserved.