Class ConcurrencyThrottleSupport
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ConcurrencyThrottleInterceptor, SyncTaskExecutor
Designed for use as a base class, with the subclass invoking
the beforeAccess() and afterAccess() methods at
appropriate points of its workflow. Note that afterAccess
should usually be called in a finally block!
The default concurrency limit of this support class is
UNBOUNDED_CONCURRENCY. Subclasses may override this default;
check the javadoc of the concrete class that you're using.
- Since:
- 1.2.5
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.commons.logging.LogTransient to optimize serialization.static final intConcurrency limit which signals that concurrency throttling has been disabled: 0.static final intConcurrency limit which signals unbounded concurrency: -1. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidTo be invoked after the main execution logic of concrete subclasses.protected voidTo be invoked before the main execution logic of concrete subclasses.intReturn the maximum number of concurrent access attempts allowed.booleanReturn whether this throttle is currently active.protected voidonAccessRejected(String msg) Triggered when access has been rejected due to the concurrency policy or due to interruption.protected voidTriggered bybeforeAccess()when the concurrency limit has been reached.voidsetConcurrencyLimit(int concurrencyLimit) Set the maximum number of concurrent access attempts allowed.
-
Field Details
-
UNBOUNDED_CONCURRENCY
public static final int UNBOUNDED_CONCURRENCYConcurrency limit which signals unbounded concurrency: -1.Setting the limit to this value permits unbounded concurrent access: that is, concurrency will not be throttled.
- See Also:
-
NO_CONCURRENCY
public static final int NO_CONCURRENCYConcurrency limit which signals that concurrency throttling has been disabled: 0.Setting the limit to this value prevents all access.
- See Also:
-
logger
protected transient org.apache.commons.logging.Log loggerTransient to optimize serialization.
-
-
Constructor Details
-
ConcurrencyThrottleSupport
public ConcurrencyThrottleSupport()
-
-
Method Details
-
setConcurrencyLimit
public void setConcurrencyLimit(int concurrencyLimit) Set the maximum number of concurrent access attempts allowed. The default of -1 indicates no concurrency limit at all.In principle, this limit can be changed at runtime, although it is generally designed as a config time setting.
NOTE: Do not switch between
-1and any concrete limit at runtime, as this will lead to inconsistent concurrency counts. A limit of-1effectively turns off concurrency counting completely. -
getConcurrencyLimit
public int getConcurrencyLimit()Return the maximum number of concurrent access attempts allowed. -
isThrottleActive
public boolean isThrottleActive()Return whether this throttle is currently active.- Returns:
trueif the concurrency limit for this instance is active- See Also:
-
beforeAccess
protected void beforeAccess()To be invoked before the main execution logic of concrete subclasses.This implementation applies the concurrency throttle.
- See Also:
-
onLimitReached
protected void onLimitReached()Triggered bybeforeAccess()when the concurrency limit has been reached. The default implementation blocks until the concurrency count allows for entering.- Since:
- 6.2.6
-
onAccessRejected
Triggered when access has been rejected due to the concurrency policy or due to interruption.Implementations will typically throw a corresponding exception. When returning normally, regular access will still be attempted.
The default implementation throws an
IllegalStateException.- Parameters:
msg- the rejection message (common exception messages are designed so that they can be appended with an identifier separated by a space in custom subclasses)- Since:
- 7.0.4
-
afterAccess
protected void afterAccess()To be invoked after the main execution logic of concrete subclasses.- See Also:
-