Skip to content

Commit f3a2f57

Browse files
committed
SimpleAsyncTaskExecutor properly respects NO_CONCURRENCY
Issue: SPR-15895 (cherry picked from commit 204ddeb)
1 parent 80bf394 commit f3a2f57

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -47,15 +47,18 @@
4747
* @see org.springframework.scheduling.commonj.WorkManagerTaskExecutor
4848
*/
4949
@SuppressWarnings("serial")
50-
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator implements AsyncListenableTaskExecutor, Serializable {
50+
public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator
51+
implements AsyncListenableTaskExecutor, Serializable {
5152

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

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

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: 4 additions & 7 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,34 +18,31 @@
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
/**
3231
* @author Rick Evans
3332
* @author Juergen Hoeller
3433
* @author Sam Brannen
3534
*/
36-
public final class SimpleAsyncTaskExecutorTests {
35+
public class SimpleAsyncTaskExecutorTests {
3736

3837
@Rule
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)