Skip to content

SimpleAsyncTaskExecutor not respect ConcurrencyThrottleSupport.NO_CONCURRENCY limit [SPR-15895] #20449

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits f3a2f57, 204ddeb

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions