Purpose: To maintain concurrency for a particular task. It is a wrappers of a semaphore that allows recursive waits by a single thread.
Responsibilities:
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final String | |
| private static final String | |
| private static final String | |
| protected transient volatile Thread | |
| private static final AtomicLong | |
| private final Date | |
| private final long | |
| public static final Map | |
| protected AtomicInteger | |
| protected boolean | |
| protected AtomicInteger | |
| protected AtomicInteger | |
| private static final Map | |
| protected static boolean | |
| protected Exception | |
| private static final Map | |
| private static final Map | |
| private static final Map | |
| private static final Map | |
| private static final Set | |
| private static final Map | |
| private final AtomicLong | |
| private final AtomicLong | |
| private final AtomicLong |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public synchronized void | |
| public void | |
| public synchronized boolean | |
| public boolean | |
| public synchronized boolean | |
| public synchronized void | |
| public synchronized boolean | |
| public synchronized boolean | acquireWithWait(boolean forMerge, int wait)
If the lock is not acquired already acquire it and return true. |
| protected void | addReadLockToReadLockManager()
The current thread has incremented the number of readers on the current cache key. |
| public void | |
| public void | |
| public static void | clearJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse()
Clear the justification why the |
| public static void | enrichStringBuildingExplainWhyThreadIsStuckInIsBuildObjectOnThreadComplete(List<Thread>
This the chaing threads that were expanded as we went down with the recursion chainOfThreadsExpandedInRecursion, ConcurrencyManager this is a lock that was deferred either by current thread or by a thread that is also itself waiting
around . This lock is what is causing us ultimately to return FALSE, because the lock is still ACUIRED
so not yet free. And the thread that owns it is also still not finished yet. finalDeferredLockCausingTrouble, Thread this is the thread that was spotted as owning/being actively owning the the deferred lock. So we can
consider this thread as being the ultimate cause of why the current thread and perhaps a hole chaing
of related threads are not evolving. But certainly the current thread. activeThreadOnDeferredLock, boolean Some threads have deferred lock managers some not. Not clear when they do. But threads doing object
building typically end up creating a deferred lock manager when they find themselves unable to acquire
an object and need to defer on the cache key. hasDeferredLockManager, StringBuilder this is what we want to populate it will allow us to build a trace to explain why the thread on the
wait for deferred lock is going nowhere. This trace will be quite important to help us interpret the
massive dumps since it is quite typical to find threads in this state. justification)When the recursive algorithm decides to return false it is because it is confronted with a cache key that had to be deferred. |
| public Thread | |
| public Date | |
| public long | |
| public static DeferredLockManager | |
| protected static Map | |
| public int | |
| public int | |
| public int | |
| private static String | |
| protected static ReadLockManager | Returns: Never null if the read lock manager does not yet exist for the current thread. otherwise its read log manager is returned.The thread for which we want to have look at the acquired read locks. thread)The method is not synchronized because for now we assume that each thread will ask for its own lock manager. |
| protected static ReadLockManager | Returns: the read lock manager for the current thread.the thread wanting its read lock manager thread)Same as |
| protected static Map | |
| public Exception | |
| public static Map | |
| public static Map | |
| public static Map | |
| public static Map | |
| public static Set | |
| public static Map | |
| public long | |
| public long | |
| public long | |
| protected static Map | |
| public boolean | |
| public static boolean | Returns: true if object is completethe current thread to be explored. It starts by being the thread that it is stuck but then it evolves
to be other that have acquired locks our main thread was needing but whcich themslves are stuck...
threads in the deffered lock chain that are going nowhere themselves. thread, Map<Thread, Thread> this prevents the algorithm going into an infinite loop of expanding the same thread more than once. recursiveSet, List<Thread> this starts by being a basket containing the current thread, but each time we go deeper it evolves to
contain the thread we will explore next. parentChainOfThreads, boolean deadLockDiagnostic)Check if the deferred locks of a thread are all released. |
| public boolean | isLockedByMergeManager()
INTERNAL: Used byt the refresh process to determine if this concurrency manager is locked by the merge process. |
| public boolean | |
| public void | |
| public void | putThreadAsWaitingToAcquireLockForReading(Thread currentThread, String
metadata to help us debug trace leaking. If we start blowing up threads we do not want the traces
created by the current thread to remain. methodName)The thread is trying to acquire a read lock but it is not being able to make process on getting the read lock. |
| public void | putThreadAsWaitingToAcquireLockForWriting(Thread thread, String methodName)
Normally this mehtod should only be called from withing the concurrency manager. |
| public synchronized void | |
| public void | releaseAllLocksAcquiredByThread(DeferredLockManager
the deferred lock manager lockManager)For the thread to release all of its locks. |
| public void | |
| public synchronized void | |
| public static DeferredLockManager | |
| protected void | removeReadLockFromReadLockManager()
The current thread is about to decrement the number of readers in cache key. |
| protected static void | removeReadLockManagerIfEmpty(Thread
the thread that wants its read lock manager destroyed if it is empty. thread)Just like we see that the satic map of deffered locks is cleared of cache values for the current thread we also want to try to keep the static map of acquired read locks by a thread light weight by removing the association between the current thread and a read lock manager whenever the read lock manager becomes empty. |
| public void | |
| public void | removeThreadNoLongerWaitingToAcquireLockForWriting(Thread thread)
The thread has acquired the lock for writing or decided to defer acquiring the lock putting this lock into its deferred lock list. |
| public void | |
| protected void | |
| public 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. |
| public static void | setJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse(String
a string that helps us understand why the recursive algorithm returned false, building object is not
yet complete. justification)See |
| protected void | |
| protected void | |
| public static void | setShouldTrackStack(boolean shouldTrackStack)
INTERNAL: This can be set during debugging to record the stacktrace when a lock is acquired. |
| public void | |
| public static boolean | |
| public String | |
| public synchronized void |
| ACQUIRE_DEFERRED_LOCK_METHOD_NAME | back to summary |
|---|---|
| private static final String ACQUIRE_DEFERRED_LOCK_METHOD_NAME | |
| ACQUIRE_METHOD_NAME | back to summary |
|---|---|
| private static final String ACQUIRE_METHOD_NAME | |
| ACQUIRE_READ_LOCK_METHOD_NAME | back to summary |
|---|---|
| private static final String ACQUIRE_READ_LOCK_METHOD_NAME | |
| ACQUIRE_WITH_WAIT_METHOD_NAME | back to summary |
|---|---|
| private static final String ACQUIRE_WITH_WAIT_METHOD_NAME | |
| activeThread | back to summary |
|---|---|
| protected transient volatile Thread activeThread | |
| CONCURRENCY_MANAGER_ID | back to summary |
|---|---|
| private static final AtomicLong CONCURRENCY_MANAGER_ID | |
| concurrencyManagerCreationDate | back to summary |
|---|---|
| private final Date concurrencyManagerCreationDate | |
| concurrencyManagerId | back to summary |
|---|---|
| private final long concurrencyManagerId | |
| DEFERRED_LOCK_MANAGERS | back to summary |
|---|---|
| public static final Map<Thread, DeferredLockManager> DEFERRED_LOCK_MANAGERS | |
| depth | back to summary |
|---|---|
| protected AtomicInteger depth | |
| lockedByMergeManager | back to summary |
|---|---|
| protected boolean lockedByMergeManager | |
| numberOfReaders | back to summary |
|---|---|
| protected AtomicInteger numberOfReaders | |
| numberOfWritersWaiting | back to summary |
|---|---|
| protected AtomicInteger numberOfWritersWaiting | |
| READ_LOCK_MANAGERS | back to summary |
|---|---|
| private static final Map<Thread, ReadLockManager> READ_LOCK_MANAGERS | |
| shouldTrackStack | back to summary |
|---|---|
| protected static boolean shouldTrackStack | |
| stack | back to summary |
|---|---|
| protected Exception stack | |
| THREADS_TO_WAIT_ON_ACQUIRE | back to summary |
|---|---|
| private static final Map<Thread, ConcurrencyManager> THREADS_TO_WAIT_ON_ACQUIRE | |
| THREADS_TO_WAIT_ON_ACQUIRE_NAME_OF_METHOD_CREATING_TRACE | back to summary |
|---|---|
| private static final Map<Thread, String> THREADS_TO_WAIT_ON_ACQUIRE_NAME_OF_METHOD_CREATING_TRACE | |
| THREADS_TO_WAIT_ON_ACQUIRE_READ_LOCK | back to summary |
|---|---|
| private static final Map<Thread, ConcurrencyManager> THREADS_TO_WAIT_ON_ACQUIRE_READ_LOCK | |
| THREADS_TO_WAIT_ON_ACQUIRE_READ_LOCK_NAME_OF_METHOD_CREATING_TRACE | back to summary |
|---|---|
| private static final Map<Thread, String> THREADS_TO_WAIT_ON_ACQUIRE_READ_LOCK_NAME_OF_METHOD_CREATING_TRACE | |
| THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS | back to summary |
|---|---|
| private static final Set<Thread> THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS | |
| THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS_BUILD_OBJECT_COMPLETE_GOES_NOWHERE | back to summary |
|---|---|
| private static final Map<Thread, String> THREADS_WAITING_TO_RELEASE_DEFERRED_LOCKS_BUILD_OBJECT_COMPLETE_GOES_NOWHERE | |
| totalNumberOfKeysAcquiredForReading | back to summary |
|---|---|
| private final AtomicLong totalNumberOfKeysAcquiredForReading | |
| totalNumberOfKeysReleasedForReading | back to summary |
|---|---|
| private final AtomicLong totalNumberOfKeysReleasedForReading | |
| totalNumberOfKeysReleasedForReadingBlewUpExceptionDueToCacheKeyHavingReachedCounterZero | back to summary |
|---|---|
| private final AtomicLong totalNumberOfKeysReleasedForReadingBlewUpExceptionDueToCacheKeyHavingReachedCounterZero | |
| ConcurrencyManager | back to summary |
|---|---|
| public ConcurrencyManager() Initialize the newly allocated instance of this class. Set the depth to zero. | |
| acquire | back to summary |
|---|---|
| public void acquire() throws ConcurrencyException Wait for all threads except the active thread. If the active thread just increment the depth. This should be called before entering a critical section. | |
| acquire | back to summary |
|---|---|
| public synchronized void acquire(boolean forMerge) throws ConcurrencyException Wait for all threads except the active thread. If the active thread just increment the depth. This should be called before entering a critical section. called with true from the merge process, if true then the refresh will not refresh the object | |
| acquireDeferredLock | back to summary |
|---|---|
| public void acquireDeferredLock() throws ConcurrencyException Add deferred lock into a hashtable to avoid deadlock | |
| acquireIfUnownedNoWait | back to summary |
|---|---|
| public synchronized boolean acquireIfUnownedNoWait(boolean forMerge) throws ConcurrencyException If the activeThread is not set, acquire it and return true. If the activeThread is set, it has been acquired already, return false. Added for Bug 5840635 Call with true from the merge process, if true then the refresh will not refresh the object. | |
| acquireNoWait | back to summary |
|---|---|
| public boolean acquireNoWait() throws ConcurrencyException If the lock is not acquired already acquire it and return true. If it has been acquired already return false Added for CR 2317 | |
| acquireNoWait | back to summary |
|---|---|
| public synchronized boolean acquireNoWait(boolean forMerge) throws ConcurrencyException If the lock is not acquired already acquire it and return true. If it has been acquired already return false Added for CR 2317 called with true from the merge process, if true then the refresh will not refresh the object | |
| acquireReadLock | back to summary |
|---|---|
| public synchronized void acquireReadLock() throws ConcurrencyException Wait on any writer. Allow concurrent reads. | |
| acquireReadLockNoWait | back to summary |
|---|---|
| public synchronized boolean acquireReadLockNoWait() If this is acquired return false otherwise acquire readlock and return true | |
| acquireWithWait | back to summary |
|---|---|
| public synchronized boolean acquireWithWait(boolean forMerge, int wait) throws ConcurrencyException If the lock is not acquired already acquire it and return true. If it has been acquired already return false Added for CR 2317 called with true from the merge process, if true then the refresh will not refresh the object | |
| addReadLockToReadLockManager | back to summary |
|---|---|
| protected void addReadLockToReadLockManager() The current thread has incremented the number of readers on the current cache key. It also wants to record into the read lock manager that this thread has acquired the cache key. This method should be user in all places where the cache key nunber of readers is incremented. | |
| checkDeferredLock | back to summary |
|---|---|
| public void checkDeferredLock() throws ConcurrencyException Check the lock state, if locked, acquire and release a deferred lock. This optimizes out the normal deferred-lock check if not locked. | |
| checkReadLock | back to summary |
|---|---|
| public void checkReadLock() throws ConcurrencyException Check the lock state, if locked, acquire and release a read lock. This optimizes out the normal read-lock check if not locked. | |
| clearJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse | back to summary |
|---|---|
| public static void clearJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse() Clear the justification why the
WHEN TO INVOKE: | |
| enrichStringBuildingExplainWhyThreadIsStuckInIsBuildObjectOnThreadComplete | back to summary |
|---|---|
| public static void enrichStringBuildingExplainWhyThreadIsStuckInIsBuildObjectOnThreadComplete(List<Thread> chainOfThreadsExpandedInRecursion, ConcurrencyManager finalDeferredLockCausingTrouble, Thread activeThreadOnDeferredLock, boolean hasDeferredLockManager, StringBuilder justification) When the recursive algorithm decides to return false it is because it is confronted with a cache key that had to be deferred. And the cache key is either being owned by a thread that did not flage itsef as being finished and waiting in the wait for deferred locks. Or the thread that ows the cache key is not playing nice - and not using deferred locks - so it has acquire the cache key, it is going about its business (e.g. committing a transaction or perhaps doing object building. Normally, but not always, in object building threads do have a lock manager, but sometimes not when they agressive acquire lock policy. )
| |
| getActiveThread | back to summary |
|---|---|
| public Thread getActiveThread() Return the active thread. | |
| getConcurrencyManagerCreationDate | back to summary |
|---|---|
| public Date getConcurrencyManagerCreationDate() Getter for | |
| getConcurrencyManagerId | back to summary |
|---|---|
| public long getConcurrencyManagerId() Getter for | |
| getDeferredLockManager | back to summary |
|---|---|
| public static DeferredLockManager getDeferredLockManager(Thread thread) Return the deferred lock manager from the thread | |
| getDeferredLockManagers | back to summary |
|---|---|
| protected static Map Return the deferred lock manager hashtable (thread - DeferredLockManager). | |
| getDepth | back to summary |
|---|---|
| public int getDepth() Return the current depth of the active thread. | |
| getNumberOfReaders | back to summary |
|---|---|
| public int getNumberOfReaders() Number of writer that want the lock. This is used to ensure that a writer is not starved. | |
| getNumberOfWritersWaiting | back to summary |
|---|---|
| public int getNumberOfWritersWaiting() Number of writers that want the lock. This is used to ensure that a writer is not starved. | |
| getPropertyRecordStackOnLock | back to summary |
|---|---|
| private static String getPropertyRecordStackOnLock() | |
| getReadLockManager | back to summary |
|---|---|
| protected static ReadLockManager getReadLockManager(Thread thread) The method is not synchronized because for now we assume that each thread will ask for its own lock manager. If we were writing a dead lock detection mechanism then a ThreadA could be trying understand the ReadLocks of a ThreadB and this would no longer be true.
| |
| getReadLockManagerEnsureResultIsNotNull | back to summary |
|---|---|
| protected static ReadLockManager getReadLockManagerEnsureResultIsNotNull(Thread thread) Same as
| |
| getReadLockManagers | back to summary |
|---|---|
| protected static Map Return the deferred lock manager hashtable (thread - DeferredLockManager). | |
| getStack | back to summary |
|---|---|
| public Exception getStack() | |
| getThreadsToWaitOnAcquire | back to summary |
|---|---|
| public static Map Getter for | |
| getThreadsToWaitOnAcquireMethodName | back to summary |
|---|---|
| public static Map Getter for | |
| getThreadsToWaitOnAcquireReadLock | back to summary |
|---|---|
| public static Map Getter for | |
| getThreadsToWaitOnAcquireReadLockMethodName | back to summary |
|---|---|
| public static Map Getter for | |
| getThreadsWaitingToReleaseDeferredLocks | back to summary |
|---|---|
| public static Set Getter for | |
| getThreadsWaitingToReleaseDeferredLocksJustification | back to summary |
|---|---|
| public static Map Getter for | |
| getTotalNumberOfKeysAcquiredForReading | back to summary |
|---|---|
| public long getTotalNumberOfKeysAcquiredForReading() Getter for | |
| getTotalNumberOfKeysReleasedForReading | back to summary |
|---|---|
| public long getTotalNumberOfKeysReleasedForReading() Getter for | |
| getTotalNumberOfKeysReleasedForReadingBlewUpExceptionDueToCacheKeyHavingReachedCounterZero | back to summary |
|---|---|
| public long getTotalNumberOfKeysReleasedForReadingBlewUpExceptionDueToCacheKeyHavingReachedCounterZero() Getter for | |
| initializeDeferredLockManagers | back to summary |
|---|---|
| protected static Map Init the deferred lock managers (thread - DeferredLockManager). | |
| isAcquired | back to summary |
|---|---|
| public boolean isAcquired() Return if a thread has acquire this manager. | |
| isBuildObjectOnThreadComplete | back to summary |
|---|---|
| public static boolean isBuildObjectOnThreadComplete(Thread thread, Map<Thread, Thread> recursiveSet, List<Thread> parentChainOfThreads, boolean deadLockDiagnostic) Check if the deferred locks of a thread are all released.
Should write dead lock diagnostic information into the
| |
| isLockedByMergeManager | back to summary |
|---|---|
| public boolean isLockedByMergeManager() INTERNAL: Used byt the refresh process to determine if this concurrency manager is locked by the merge process. If it is then the refresh should not refresh the object | |
| isNested | back to summary |
|---|---|
| public boolean isNested() Return if this manager is within a nested acquire. | |
| putDeferredLock | back to summary |
|---|---|
| public void putDeferredLock(Thread thread, DeferredLockManager lockManager) | |
| putThreadAsWaitingToAcquireLockForReading | back to summary |
|---|---|
| public void putThreadAsWaitingToAcquireLockForReading(Thread currentThread, String methodName) The thread is trying to acquire a read lock but it is not being able to make process on getting the read lock.
| |
| putThreadAsWaitingToAcquireLockForWriting | back to summary |
|---|---|
| public void putThreadAsWaitingToAcquireLockForWriting(Thread thread, String methodName) Normally this mehtod should only be called from withing the concurrency manager. However the write lock manager while it is building clones also does some while loop waiting to try to acquire a cache key this acquiring logic is not being managed directly inside of the wait manager. | |
| release | back to summary |
|---|---|
| public synchronized void release() throws ConcurrencyException Decrement the depth for the active thread. Assume the current thread is the active one. Raise an error if the depth become < 0. The notify will release the first thread waiting on the object, if no threads are waiting it will do nothing. | |
| releaseAllLocksAcquiredByThread | back to summary |
|---|---|
| public void releaseAllLocksAcquiredByThread(DeferredLockManager lockManager) For the thread to release all of its locks.
| |
| releaseDeferredLock | back to summary |
|---|---|
| public void releaseDeferredLock() throws ConcurrencyException Release the deferred lock. This uses a deadlock detection and resolution algorithm to avoid cache deadlocks. The deferred lock manager keeps track of the lock for a thread, so that other thread know when a deadlock has occurred and can resolve it. | |
| releaseReadLock | back to summary |
|---|---|
| public synchronized void releaseReadLock() throws ConcurrencyException Decrement the number of readers. Used to allow concurrent reads. | |
| removeDeferredLockManager | back to summary |
|---|---|
| public static DeferredLockManager removeDeferredLockManager(Thread thread) Remove the deferred lock manager for the thread | |
| removeReadLockFromReadLockManager | back to summary |
|---|---|
| protected void removeReadLockFromReadLockManager() The current thread is about to decrement the number of readers in cache key. The thread also wants to update the read lock manager and remove the cache key that has previously been aquired from there. | |
| removeReadLockManagerIfEmpty | back to summary |
|---|---|
| protected static void removeReadLockManagerIfEmpty(Thread thread) Just like we see that the satic map of deffered locks is cleared of cache values for the current thread we also want to try to keep the static map of acquired read locks by a thread light weight by removing the association between the current thread and a read lock manager whenever the read lock manager becomes empty.
| |
| removeThreadNoLongerWaitingToAcquireLockForReading | back to summary |
|---|---|
| public void removeThreadNoLongerWaitingToAcquireLockForReading(Thread thread) | |
| removeThreadNoLongerWaitingToAcquireLockForWriting | back to summary |
|---|---|
| public void removeThreadNoLongerWaitingToAcquireLockForWriting(Thread thread) The thread has acquired the lock for writing or decided to defer acquiring the lock putting this lock into its deferred lock list. | |
| setActiveThread | back to summary |
|---|---|
| public void setActiveThread(Thread activeThread) Set the active thread. | |
| setDepth | back to summary |
|---|---|
| protected void setDepth(int depth) Set the current depth of the active thread. | |
| setIsLockedByMergeManager | back to summary |
|---|---|
| public 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. | |
| setJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse | back to summary |
|---|---|
| public static void setJustificationWhyMethodIsBuildingObjectCompleteReturnsFalse(String justification) See
| |
| setNumberOfReaders | back to summary |
|---|---|
| protected void setNumberOfReaders(int numberOfReaders) Track the number of readers. | |
| setNumberOfWritersWaiting | back to summary |
|---|---|
| protected void setNumberOfWritersWaiting(int numberOfWritersWaiting) Number of writers that want the lock. This is used to ensure that a writer is not starved. | |
| setShouldTrackStack | back to summary |
|---|---|
| public static void setShouldTrackStack(boolean shouldTrackStack) INTERNAL: This can be set during debugging to record the stacktrace when a lock is acquired. Then once IdentityMapAccessor.printIdentityMapLocks() is called the stack call for each lock will be printed as well. Because locking issues are usually quite time sensitive setting this flag may inadvertently remove the deadlock because of the change in timings. There is also a system level property for this setting. "eclipselink.cache.record-stack-on-lock" | |
| setStack | back to summary |
|---|---|
| public void setStack(Exception stack) | |
| shouldTrackStack | back to summary |
|---|---|
| public static boolean shouldTrackStack() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Print the nested depth.
| |
| transitionToDeferredLock | back to summary |
|---|---|
| public synchronized void transitionToDeferredLock() | |