Skip to content

Commit 0f70770

Browse files
committed
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
1 parent f526b23 commit 0f70770

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ protected Executor getExecutor(Supplier<Executor> fallback, Consumer<Executor> c
114114
}
115115
else if (this.registration != null) {
116116
ThreadPoolTaskExecutor registeredTaskExecutor = this.registration.getTaskExecutor();
117-
customizer.accept(registeredTaskExecutor);
117+
if (!this.registration.isExternallyDefined()) {
118+
customizer.accept(registeredTaskExecutor);
119+
}
118120
return registeredTaskExecutor;
119121
}
120122
else {

spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -29,6 +29,8 @@
2929
*/
3030
public class TaskExecutorRegistration {
3131

32+
private final boolean externallyDefined;
33+
3234
private final ThreadPoolTaskExecutor taskExecutor;
3335

3436
@Nullable
@@ -49,6 +51,7 @@ public class TaskExecutorRegistration {
4951
* {@link ThreadPoolTaskExecutor}.
5052
*/
5153
public TaskExecutorRegistration() {
54+
this.externallyDefined = false;
5255
this.taskExecutor = new ThreadPoolTaskExecutor();
5356
this.taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
5457
this.taskExecutor.setAllowCoreThreadTimeOut(true);
@@ -60,6 +63,7 @@ public TaskExecutorRegistration() {
6063
* @param taskExecutor the executor to use
6164
*/
6265
public TaskExecutorRegistration(ThreadPoolTaskExecutor taskExecutor) {
66+
this.externallyDefined = true;
6367
Assert.notNull(taskExecutor, "ThreadPoolTaskExecutor must not be null");
6468
this.taskExecutor = taskExecutor;
6569
}
@@ -122,6 +126,15 @@ public TaskExecutorRegistration queueCapacity(int queueCapacity) {
122126
return this;
123127
}
124128

129+
/**
130+
* Specify if the task executor has been supplied.
131+
* @return {@code true} if the task executor was provided, {@code false} if
132+
* it has been created internally
133+
* @since 6.2
134+
*/
135+
protected boolean isExternallyDefined() {
136+
return this.externallyDefined;
137+
}
125138

126139
protected ThreadPoolTaskExecutor getTaskExecutor() {
127140
if (this.corePoolSize != null) {

spring-messaging/src/test/java/org/springframework/messaging/simp/config/ChannelRegistrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,14 @@ void taskRegistrationCreatesDefaultInstance() {
7373
}
7474

7575
@Test
76-
void taskRegistrationWithExistingThreadPoolTaskExecutor() {
76+
void taskRegistrationWithExistingThreadPoolTaskExecutorDoesNotInvokeCustomizer() {
7777
ThreadPoolTaskExecutor existingExecutor = mock(ThreadPoolTaskExecutor.class);
7878
ChannelRegistration registration = new ChannelRegistration();
7979
registration.taskExecutor(existingExecutor);
8080
assertThat(registration.hasExecutor()).isTrue();
8181
Executor executor = registration.getExecutor(this.fallback, this.customizer);
8282
assertThat(executor).isSameAs(existingExecutor);
83-
verifyNoInteractions(this.fallback);
84-
verify(this.customizer).accept(executor);
83+
verifyNoInteractions(this.fallback, this.customizer);
8584
}
8685

8786
@Test

0 commit comments

Comments
 (0)