Top Description Fields Constructors Methods
org.springframework.util

public abstract Class ConcurrencyThrottleSupport

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.springframework.core.task.SimpleAsyncTaskExecutor.ConcurrencyThrottleAdapter
Annotations
@SuppressWarnings:serial
Imports
java.io.IOException, .ObjectInputStream, .Serializable, java.util.concurrent.locks.Condition, .Lock, .ReentrantLock, org.apache.commons.logging.Log, .LogFactory

Support class for throttling concurrent access to a specific resource.

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 -1 ("unbounded concurrency"). Subclasses may override this default; check the javadoc of the concrete class that you're using.

Author
Juergen Hoeller
Since
1.2.5
See Also
setConcurrencyLimit, beforeAccess(), afterAccess(), org.springframework.aop.interceptor.ConcurrencyThrottleInterceptor, java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final Condition
private int
private int
private final Lock
protected transient Log
logger

Transient to optimize serialization.

public static final int
NO_CONCURRENCY

Switch concurrency 'off': that is, don't allow any concurrent invocations.

public static final int
UNBOUNDED_CONCURRENCY

Permit any number of concurrent invocations: that is, don't throttle concurrency.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
afterAccess()

To be invoked after the main execution logic of concrete subclasses.

protected void
beforeAccess()

To be invoked before the main execution logic of concrete subclasses.

public int
getConcurrencyLimit()

Return the maximum number of concurrent access attempts allowed.

public boolean

Returns:

true if the concurrency limit for this instance is active
isThrottleActive
()

Return whether this throttle is currently active.

private void
public void
setConcurrencyLimit(int concurrencyLimit)

Set the maximum number of concurrent access attempts allowed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

concurrencyConditionback to summary
private final Condition concurrencyCondition
concurrencyCountback to summary
private int concurrencyCount
concurrencyLimitback to summary
private int concurrencyLimit
concurrencyLockback to summary
private final Lock concurrencyLock
loggerback to summary
protected transient Log logger

Transient to optimize serialization.

NO_CONCURRENCYback to summary
public static final int NO_CONCURRENCY

Switch concurrency 'off': that is, don't allow any concurrent invocations.

UNBOUNDED_CONCURRENCYback to summary
public static final int UNBOUNDED_CONCURRENCY

Permit any number of concurrent invocations: that is, don't throttle concurrency.

Constructor Detail

ConcurrencyThrottleSupportback to summary
public ConcurrencyThrottleSupport()

Method Detail

afterAccessback to summary
protected void afterAccess()

To be invoked after the main execution logic of concrete subclasses.

See Also
beforeAccess()
beforeAccessback to summary
protected void beforeAccess()

To be invoked before the main execution logic of concrete subclasses.

This implementation applies the concurrency throttle.

See Also
afterAccess()
getConcurrencyLimitback to summary
public int getConcurrencyLimit()

Return the maximum number of concurrent access attempts allowed.

isThrottleActiveback to summary
public boolean isThrottleActive()

Return whether this throttle is currently active.

Returns:boolean

true if the concurrency limit for this instance is active

See Also
getConcurrencyLimit()
readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException
setConcurrencyLimitback to summary
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 -1 and any concrete limit at runtime, as this will lead to inconsistent concurrency counts: A limit of -1 effectively turns off concurrency counting completely.