Code alignment between ThreadPoolTaskExecutor and ThreadPoolTaskScheduler
See gh-26700
This commit is contained in:
parent
531174258c
commit
d3b1c4f62b
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -84,10 +84,10 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||||
*/
|
*/
|
||||||
public void setPoolSize(int poolSize) {
|
public void setPoolSize(int poolSize) {
|
||||||
Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher");
|
Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher");
|
||||||
this.poolSize = poolSize;
|
|
||||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setCorePoolSize(poolSize);
|
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setCorePoolSize(poolSize);
|
||||||
}
|
}
|
||||||
|
this.poolSize = poolSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -97,13 +97,13 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||||
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
||||||
*/
|
*/
|
||||||
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
|
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
|
||||||
this.removeOnCancelPolicy = removeOnCancelPolicy;
|
|
||||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
|
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
|
||||||
}
|
}
|
||||||
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
|
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
|
||||||
logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
|
logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
|
||||||
}
|
}
|
||||||
|
this.removeOnCancelPolicy = removeOnCancelPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2020 the original author or authors.
|
* Copyright 2002-2021 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,6 +19,7 @@ package org.springframework.scheduling.concurrent;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -32,6 +33,7 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||||
|
|
||||||
private final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
private final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AsyncListenableTaskExecutor buildExecutor() {
|
protected AsyncListenableTaskExecutor buildExecutor() {
|
||||||
executor.setThreadNamePrefix(this.threadNamePrefix);
|
executor.setThreadNamePrefix(this.threadNamePrefix);
|
||||||
|
|
@ -40,6 +42,7 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void modifyCorePoolSizeWhileRunning() {
|
void modifyCorePoolSizeWhileRunning() {
|
||||||
assertThat(executor.getCorePoolSize()).isEqualTo(1);
|
assertThat(executor.getCorePoolSize()).isEqualTo(1);
|
||||||
|
|
@ -108,4 +111,5 @@ class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||||
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
|
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
|
||||||
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
|
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue