Skip to content

Commit d3b1c4f

Browse files
committed
Code alignment between ThreadPoolTaskExecutor and ThreadPoolTaskScheduler
See gh-26700
1 parent 5311742 commit d3b1c4f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -84,10 +84,10 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
8484
*/
8585
public void setPoolSize(int poolSize) {
8686
Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher");
87-
this.poolSize = poolSize;
8887
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
8988
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setCorePoolSize(poolSize);
9089
}
90+
this.poolSize = poolSize;
9191
}
9292

9393
/**
@@ -97,13 +97,13 @@ public void setPoolSize(int poolSize) {
9797
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
9898
*/
9999
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
100-
this.removeOnCancelPolicy = removeOnCancelPolicy;
101100
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
102101
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
103102
}
104103
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
105104
logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
106105
}
106+
this.removeOnCancelPolicy = removeOnCancelPolicy;
107107
}
108108

109109
/**

spring-context/src/test/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutorTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -19,6 +19,7 @@
1919
import java.util.concurrent.TimeUnit;
2020

2121
import org.junit.jupiter.api.Test;
22+
2223
import org.springframework.core.task.AsyncListenableTaskExecutor;
2324

2425
import static org.assertj.core.api.Assertions.assertThat;
@@ -32,6 +33,7 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
3233

3334
private final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
3435

36+
3537
@Override
3638
protected AsyncListenableTaskExecutor buildExecutor() {
3739
executor.setThreadNamePrefix(this.threadNamePrefix);
@@ -40,6 +42,7 @@ protected AsyncListenableTaskExecutor buildExecutor() {
4042
return executor;
4143
}
4244

45+
4346
@Test
4447
void modifyCorePoolSizeWhileRunning() {
4548
assertThat(executor.getCorePoolSize()).isEqualTo(1);
@@ -108,4 +111,5 @@ void modifyKeepAliveSecondsWithInvalidValueWhileRunning() {
108111
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
109112
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
110113
}
114+
111115
}

0 commit comments

Comments
 (0)