Description
Simon Wong opened SPR-15895 and commented
When I set the SimpleAsyncTaskExecutor
setConcurrencyLimit
with value ConcurrencyThrottleSupport.NO_CONCURRENCY
(i.e. value = 0), the execute
of SimpleAsyncTaskExecutor
will not take NO_CONCURRENCY
in consideration. The Runnable
will always be executed in all cases.
public void execute(Runnable task, long startTimeout) {
Assert.notNull(task, "Runnable must not be null");
Runnable taskToUse = (this.taskDecorator != null ? this.taskDecorator.decorate(task) : task);
if (isThrottleActive() && startTimeout > TIMEOUT_IMMEDIATE) {
this.concurrencyThrottle.beforeAccess();
doExecute(new ConcurrencyThrottlingRunnable(taskToUse));
}
else {
doExecute(taskToUse);
}
}
The root cause is isThrottleActive()
will always returns false
as the concurrent limit = 0 in this case, hence ConcurrencyThrottleAdapter
will not be processed.
This is also the reason why the 1st test case SimpleAsyncTaskExecutorTests
cannotExecuteWhenConcurrencyIsSwitchedOff
is disabled by the SPF committer.
The current workaround is SimpleAsyncTaskExecutor.setConcurrencyLimit(1)
.
BTW, NO_CONCURRENCY = 0
is somehow wrong in definition. No currency should means there should be one invocation of method at a time, other invocations should be waited. That means NO_CONCURRENCY
should have a value of 1
instead.
Affects: 4.3.10
Issue Links:
- Migrate remaining JUnit 3 based tests to JUnit 4 [SPR-13514] #18091 Migrate remaining JUnit 3 based tests to JUnit 4