Package org.springframework.util

# Class ConcurrencyThrottleSupport

java.lang.Object
org.springframework.util.ConcurrencyThrottleSupport

All Implemented Interfaces:
  `Serializable`

public abstract class ConcurrencyThrottleSupport extends Object implements Serializable
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.

Since:
  1.2.5
Author:
  Juergen Hoeller
See Also:
  - `setConcurrencyLimit(int)`
  - `beforeAccess()`
  - `afterAccess()`
  - `org.springframework.aop.interceptor.ConcurrencyThrottleInterceptor`
  - `Serializable`
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected org.apache.commons.logging.Log`
`logger`
Transient to optimize serialization.
`static final int`
`NO_CONCURRENCY`
Switch concurrency 'off': that is, don't allow any concurrent invocations.
`static final int`
`UNBOUNDED_CONCURRENCY`
Permit any number of concurrent invocations: that is, don't throttle concurrency.

## Constructor Summary

Constructors
Constructor
Description
`ConcurrencyThrottleSupport()`

## Method Summary

Modifier and Type
Method
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.
`int`
`getConcurrencyLimit()`
Return the maximum number of concurrent access attempts allowed.
`boolean`
`isThrottleActive()`
Return whether this throttle is currently active.
`protected void`
`onLimitReached()`
Triggered by `beforeAccess()` when the concurrency limit has been reached.
`void`
`setConcurrencyLimit(int concurrencyLimit)`
Set the maximum number of concurrent access attempts allowed.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### UNBOUNDED_CONCURRENCY

public static final int UNBOUNDED_CONCURRENCY
Permit any number of concurrent invocations: that is, don't throttle concurrency.

See Also:
  - Constant Field Values

### NO_CONCURRENCY

public static final int NO_CONCURRENCY
Switch concurrency 'off': that is, don't allow any concurrent invocations.

See Also:
  - Constant Field Values

### logger

protected transient org.apache.commons.logging.Log logger
Transient 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 -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.

### 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:
  `true` if the concurrency limit for this instance is active
See Also:
  - `getConcurrencyLimit()`

### beforeAccess

protected void beforeAccess()
To be invoked before the main execution logic of concrete subclasses.

This implementation applies the concurrency throttle.

See Also:
  - `onLimitReached()`
  - `afterAccess()`

### onLimitReached

protected void onLimitReached()
Triggered by `beforeAccess()` when the concurrency limit has been reached. The default implementation blocks until the concurrency count allows for entering.

Since:
  6.2.6

### afterAccess

protected void afterAccess()
To be invoked after the main execution logic of concrete subclasses.

See Also:
  - `beforeAccess()`