Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-15895

SimpleAsyncTaskExecutor not respect ConcurrencyThrottleSupport.NO_CONCURRENCY limit

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 4.3.10
    • Fix Version/s: 4.3.11, 5.0 RC4
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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.

      SimpleAsyncTaskExecutor.java
      	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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              simonwg Simon Wong
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 37 weeks, 6 days ago