Class ConcurrencySemaphore
- java.lang.Object
-
- org.eclipse.persistence.internal.helper.ConcurrencySemaphore
-
public class ConcurrencySemaphore extends Object
-
-
Constructor Summary
Constructors Constructor Description ConcurrencySemaphore(ThreadLocal<Boolean> threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore, int noOfThreadsAllowedToExecuteInParallel, Semaphore semaphoreOfThreadsAllowedToExecuteInParallel, Object outerObject, String logMessageKey)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acquireSemaphoreIfAppropriate(boolean useSemaphore)
Do nothing if the semaphore has already been acquired by this thread in a higher recursive call or if the configuration to acquire the slow down semaphore is not active.void
releaseSemaphoreAllowOtherThreadsToStartDoingObjectBuilding(boolean semaphoreWasAcquired)
If the call toacquireSemaphoreIfAppropriate(boolean)
returned true implying the current thread acquire the semaphore, the same thread on the same method is mandated to release the semaphore.
-
-
-
Constructor Detail
-
ConcurrencySemaphore
public ConcurrencySemaphore(ThreadLocal<Boolean> threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore, int noOfThreadsAllowedToExecuteInParallel, Semaphore semaphoreOfThreadsAllowedToExecuteInParallel, Object outerObject, String logMessageKey)
Constructor to createConcurrencySemaphore(java.lang.ThreadLocal<java.lang.Boolean>, int, java.util.concurrent.Semaphore, java.lang.Object, java.lang.String)
- Parameters:
threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore
- Thread local variable that the code to acquire a semaphore can check to make sure it does not try to acquire twice the same semaphore (e.g. in case the object building algorithm is recursive).noOfThreadsAllowedToExecuteInParallel
- Max number of threads to acquire semaphore.semaphoreOfThreadsAllowedToExecuteInParallel
- Semaphore used to control.outerObject
- Reference to outer object where is this semaphore used.logMessageKey
- Log message key fromTraceLocalization
-
-
Method Detail
-
acquireSemaphoreIfAppropriate
public boolean acquireSemaphoreIfAppropriate(boolean useSemaphore)
Do nothing if the semaphore has already been acquired by this thread in a higher recursive call or if the configuration to acquire the slow down semaphore is not active. Otherwise, try to acquire the semaphore- Parameters:
useSemaphore
- TRUE to use semaphore, FALSE don't use it.- Returns:
- FALSE is returned if we do not want to be using the semaphore. FALSE is also returned if the current thread has acquire the semaphore in an upper level recursive stack call. TRUE is returned if and only using the semaphore is desired and we succeed acquiring the semaphore.
-
releaseSemaphoreAllowOtherThreadsToStartDoingObjectBuilding
public void releaseSemaphoreAllowOtherThreadsToStartDoingObjectBuilding(boolean semaphoreWasAcquired)
If the call toacquireSemaphoreIfAppropriate(boolean)
returned true implying the current thread acquire the semaphore, the same thread on the same method is mandated to release the semaphore.- Parameters:
semaphoreWasAcquired
- flag that tells us if the current thread had successfully acquired semaphore if the flag is true then the semaphore will be released and given resources again.
-
-