Top Fields Constructors Methods
org.eclipse.persistence.internal.helper

public Class ConcurrencySemaphore

extends Object
Class Inheritance
Imports
org.eclipse.persistence.exceptions.ConcurrencyException, org.eclipse.persistence.internal.localization.TraceLocalization, org.eclipse.persistence.logging.AbstractSessionLog, .SessionLog, java.util.concurrent.Semaphore, .TimeUnit

Field Summary

Modifier and TypeField and Description
private String
private final long
private int
private Object
private Semaphore
private ThreadLocal<Boolean>
private final long

Constructor Summary

AccessConstructor and Description
public
ConcurrencySemaphore(ThreadLocal<Boolean>
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).
threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore
,
int
Max number of threads to acquire semaphore.
noOfThreadsAllowedToExecuteInParallel
,
Semaphore
Semaphore used to control.
semaphoreOfThreadsAllowedToExecuteInParallel
,
Object
Reference to outer object where is this semaphore used.
outerObject
,
String logMessageKey)

Constructor to create ConcurrencySemaphore

Method Summary

Modifier and TypeMethod and Description
public boolean

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.
acquireSemaphoreIfAppropriate
(boolean
TRUE to use semaphore, FALSE don't use it.
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.

public void
releaseSemaphoreAllowOtherThreadsToStartDoingObjectBuilding(boolean
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.
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logMessageKeyback to summary
private String logMessageKey
MAX_TIME_PERMITback to summary
private final long MAX_TIME_PERMIT
noOfThreadsback to summary
private int noOfThreads
outerObjectback to summary
private Object outerObject
semaphoreback to summary
private Semaphore semaphore
threadLocalback to summary
private ThreadLocal<Boolean> threadLocal
TIMEOUT_BETWEEN_LOG_MESSAGESback to summary
private final long TIMEOUT_BETWEEN_LOG_MESSAGES

Constructor Detail

ConcurrencySemaphoreback to summary
public ConcurrencySemaphore(ThreadLocal<Boolean> threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore, int noOfThreadsAllowedToExecuteInParallel, Semaphore semaphoreOfThreadsAllowedToExecuteInParallel, Object outerObject, String logMessageKey)

Constructor to create ConcurrencySemaphore

Parameters
threadLocalVarControlIfCurrentThreadHasAcquiredSemaphore:ThreadLocal<Boolean>

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:int

Max number of threads to acquire semaphore.

semaphoreOfThreadsAllowedToExecuteInParallel:Semaphore

Semaphore used to control.

outerObject:Object

Reference to outer object where is this semaphore used.

logMessageKey:String

Log message key from org.eclipse.persistence.internal.localization.TraceLocalization

Method Detail

acquireSemaphoreIfAppropriateback to summary
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:boolean

TRUE to use semaphore, FALSE don't use it.

Returns:boolean

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.

releaseSemaphoreAllowOtherThreadsToStartDoingObjectBuildingback to summary
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:boolean

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.