Stop setting a thread name prefix for externally defined Executors
This commit updates the WebSocket message broker configuration to stop setting a thread name prefix for externally defined Executors. This used to apply to: * clientInboundChannel with a thread name prefix of "clientInboundChannel-". * clientOutboundChannel with a thread name prefix of "clientOutboundChannel-". * brokerChannel with a thread name prefix of "brokerChannel-". Closes gh-32132
This commit is contained in:
@@ -114,7 +114,9 @@ public class ChannelRegistration {
|
||||
}
|
||||
else if (this.registration != null) {
|
||||
ThreadPoolTaskExecutor registeredTaskExecutor = this.registration.getTaskExecutor();
|
||||
customizer.accept(registeredTaskExecutor);
|
||||
if (!this.registration.isExternallyDefined()) {
|
||||
customizer.accept(registeredTaskExecutor);
|
||||
}
|
||||
return registeredTaskExecutor;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class TaskExecutorRegistration {
|
||||
|
||||
private final boolean externallyDefined;
|
||||
|
||||
private final ThreadPoolTaskExecutor taskExecutor;
|
||||
|
||||
@Nullable
|
||||
@@ -49,6 +51,7 @@ public class TaskExecutorRegistration {
|
||||
* {@link ThreadPoolTaskExecutor}.
|
||||
*/
|
||||
public TaskExecutorRegistration() {
|
||||
this.externallyDefined = false;
|
||||
this.taskExecutor = new ThreadPoolTaskExecutor();
|
||||
this.taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
|
||||
this.taskExecutor.setAllowCoreThreadTimeOut(true);
|
||||
@@ -60,6 +63,7 @@ public class TaskExecutorRegistration {
|
||||
* @param taskExecutor the executor to use
|
||||
*/
|
||||
public TaskExecutorRegistration(ThreadPoolTaskExecutor taskExecutor) {
|
||||
this.externallyDefined = true;
|
||||
Assert.notNull(taskExecutor, "ThreadPoolTaskExecutor must not be null");
|
||||
this.taskExecutor = taskExecutor;
|
||||
}
|
||||
@@ -122,6 +126,15 @@ public class TaskExecutorRegistration {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if the task executor has been supplied.
|
||||
* @return {@code true} if the task executor was provided, {@code false} if
|
||||
* it has been created internally
|
||||
* @since 6.2
|
||||
*/
|
||||
protected boolean isExternallyDefined() {
|
||||
return this.externallyDefined;
|
||||
}
|
||||
|
||||
protected ThreadPoolTaskExecutor getTaskExecutor() {
|
||||
if (this.corePoolSize != null) {
|
||||
|
||||
@@ -73,15 +73,14 @@ class ChannelRegistrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskRegistrationWithExistingThreadPoolTaskExecutor() {
|
||||
void taskRegistrationWithExistingThreadPoolTaskExecutorDoesNotInvokeCustomizer() {
|
||||
ThreadPoolTaskExecutor existingExecutor = mock(ThreadPoolTaskExecutor.class);
|
||||
ChannelRegistration registration = new ChannelRegistration();
|
||||
registration.taskExecutor(existingExecutor);
|
||||
assertThat(registration.hasExecutor()).isTrue();
|
||||
Executor executor = registration.getExecutor(this.fallback, this.customizer);
|
||||
assertThat(executor).isSameAs(existingExecutor);
|
||||
verifyNoInteractions(this.fallback);
|
||||
verify(this.customizer).accept(executor);
|
||||
verifyNoInteractions(this.fallback, this.customizer);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user