Skip to content

Commit 204ddeb

Browse files
committed
SimpleAsyncTaskExecutor properly respects NO_CONCURRENCY
Issue: SPR-15895
1 parent 678a786 commit 204ddeb

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@
4848
* @see org.springframework.scheduling.commonj.WorkManagerTaskExecutor
4949
*/
5050
@SuppressWarnings("serial")
51-
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator implements AsyncListenableTaskExecutor, Serializable {
51+
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
52+
implements AsyncListenableTaskExecutor, Serializable {
5253

5354
/**
5455
* Permit any number of concurrent invocations: that is, don't throttle concurrency.
56+
* @see ConcurrencyThrottleSupport#UNBOUNDED_CONCURRENCY
5557
*/
5658
public static final int UNBOUNDED_CONCURRENCY = ConcurrencyThrottleSupport.UNBOUNDED_CONCURRENCY;
5759

5860
/**
5961
* Switch concurrency 'off': that is, don't allow any concurrent invocations.
62+
* @see ConcurrencyThrottleSupport#NO_CONCURRENCY
6063
*/
6164
public static final int NO_CONCURRENCY = ConcurrencyThrottleSupport.NO_CONCURRENCY;
6265

spring-core/src/main/java/org/springframework/util/ConcurrencyThrottleSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@ public int getConcurrencyLimit() {
9393
* @see #getConcurrencyLimit()
9494
*/
9595
public boolean isThrottleActive() {
96-
return (this.concurrencyLimit > 0);
96+
return (this.concurrencyLimit >= 0);
9797
}
9898

9999

spring-core/src/test/java/org/springframework/core/task/SimpleAsyncTaskExecutorTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,14 +18,13 @@
1818

1919
import java.util.concurrent.ThreadFactory;
2020

21-
import org.junit.Ignore;
2221
import org.junit.Rule;
2322
import org.junit.Test;
2423
import org.junit.rules.ExpectedException;
24+
2525
import org.springframework.util.ConcurrencyThrottleSupport;
2626

2727
import static org.hamcrest.CoreMatchers.*;
28-
2928
import static org.junit.Assert.*;
3029

3130
/**
@@ -39,13 +38,11 @@ public class SimpleAsyncTaskExecutorTests {
3938
public final ExpectedException exception = ExpectedException.none();
4039

4140

42-
// TODO Determine why task is executed when concurrency is switched off.
43-
@Ignore("Disabled because task is still executed when concurrency is switched off")
4441
@Test
4542
public void cannotExecuteWhenConcurrencyIsSwitchedOff() throws Exception {
4643
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
4744
executor.setConcurrencyLimit(ConcurrencyThrottleSupport.NO_CONCURRENCY);
48-
assertFalse(executor.isThrottleActive());
45+
assertTrue(executor.isThrottleActive());
4946
exception.expect(IllegalStateException.class);
5047
executor.execute(new NoOpRunnable());
5148
}

0 commit comments

Comments
 (0)