R
- the return type of real-method that is executed by circuit breakerpublic class LimitedConcurrentExecutionsStrategy<R> extends Object implements BreakStrategy<R>
BreakStrategy
which causes the circuit breaker to break (not execute the Task) in
case all tasks currently running inside the circuit breaker reaches the allowed maximum (defined by
maxSupportedExecutions constructor param).
In constructor you define maximum number of allowed concurrent executions of real_method .
For example this strategy:
new LimitedConcurrentExecutionsStrategy(10);
breaks (not allows execution of target-method) in there are currently 10 other threads that started execution of target-method and the method did not yet return a value. In this case circuit breaker would executed a break handler to provide fallback behaviour. If the number of task at the moment was less than 10, Task (real-method) would be executed normal.
NOTE: in above example, if the average was above 1000ms than this strategy would return false to circuit breaker
and circuit breaker would execute BreakHandler
to handle this
situation
Modifier and Type | Field and Description |
---|---|
protected long |
maxSupportedExecutions
Protected access to allow extending classes to dynamically change it,
e.g. via MBean
|
Constructor and Description |
---|
LimitedConcurrentExecutionsStrategy(long maxSupportedExecutions) |
Modifier and Type | Method and Description |
---|---|
boolean |
shouldBreak(Task<R> task,
ExecutionContext<R> executionContext)
Returns true if "break" should happen, so that the Task (target-method) does not execute and circuit
breaker executes fallback break handler.
|
protected long maxSupportedExecutions
public LimitedConcurrentExecutionsStrategy(long maxSupportedExecutions)
public boolean shouldBreak(Task<R> task, ExecutionContext<R> executionContext)
BreakStrategy
shouldBreak
in interface BreakStrategy<R>
task
- the task for execution of which this break strategy was calledexecutionContext
- current execution contextCopyright © 2017. All rights reserved.