Class ConcurrencySemaphore


  • public class ConcurrencySemaphore
    extends Object
    • Constructor Detail

      • ConcurrencySemaphore

        public ConcurrencySemaphore​(ThreadLocal<Boolean> threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore,
                                    int noOfThreadsAllowedToExecuteInParallel,
                                    Semaphore semaphoreOfThreadsAllowedToExecuteInParallel,
                                    Object outerObject,
                                    String logMessageKey)
        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 from TraceLocalization
    • 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 to acquireSemaphoreIfAppropriate(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.