Skip to content

Commit e09c5fd

Browse files
committed
Use TaskExecutor instead of ThreadPoolTaskExecutor
Closes gh-22943
1 parent 0b2fcbf commit e09c5fd

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.context.ApplicationContextAware;
2929
import org.springframework.context.annotation.Bean;
3030
import org.springframework.context.event.SmartApplicationListener;
31+
import org.springframework.core.task.TaskExecutor;
3132
import org.springframework.lang.Nullable;
3233
import org.springframework.messaging.MessageHandler;
3334
import org.springframework.messaging.converter.ByteArrayMessageConverter;
@@ -139,7 +140,7 @@ public AbstractSubscribableChannel clientInboundChannel() {
139140
}
140141

141142
@Bean
142-
public ThreadPoolTaskExecutor clientInboundChannelExecutor() {
143+
public TaskExecutor clientInboundChannelExecutor() {
143144
TaskExecutorRegistration reg = getClientInboundChannelRegistration().taskExecutor();
144145
ThreadPoolTaskExecutor executor = reg.getTaskExecutor();
145146
executor.setThreadNamePrefix("clientInboundChannel-");
@@ -175,7 +176,7 @@ public AbstractSubscribableChannel clientOutboundChannel() {
175176
}
176177

177178
@Bean
178-
public ThreadPoolTaskExecutor clientOutboundChannelExecutor() {
179+
public TaskExecutor clientOutboundChannelExecutor() {
179180
TaskExecutorRegistration reg = getClientOutboundChannelRegistration().taskExecutor();
180181
ThreadPoolTaskExecutor executor = reg.getTaskExecutor();
181182
executor.setThreadNamePrefix("clientOutboundChannel-");
@@ -211,7 +212,7 @@ public AbstractSubscribableChannel brokerChannel() {
211212
}
212213

213214
@Bean
214-
public ThreadPoolTaskExecutor brokerChannelExecutor() {
215+
public TaskExecutor brokerChannelExecutor() {
215216
ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration();
216217
ThreadPoolTaskExecutor executor;
217218
if (reg.hasTaskExecutor()) {

spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketMessageBrokerStats.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import java.time.Instant;
2121
import java.util.concurrent.Executor;
2222
import java.util.concurrent.ScheduledFuture;
23-
import java.util.concurrent.ThreadPoolExecutor;
2423
import java.util.concurrent.TimeUnit;
2524

2625
import org.apache.commons.logging.Log;
2726
import org.apache.commons.logging.LogFactory;
2827

28+
import org.springframework.core.task.TaskExecutor;
2929
import org.springframework.lang.Nullable;
3030
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
3131
import org.springframework.scheduling.TaskScheduler;
@@ -66,10 +66,10 @@ public class WebSocketMessageBrokerStats {
6666
private StompBrokerRelayMessageHandler stompBrokerRelay;
6767

6868
@Nullable
69-
private ThreadPoolExecutor inboundChannelExecutor;
69+
private TaskExecutor inboundChannelExecutor;
7070

7171
@Nullable
72-
private ThreadPoolExecutor outboundChannelExecutor;
72+
private TaskExecutor outboundChannelExecutor;
7373

7474
@Nullable
7575
private TaskScheduler sockJsTaskScheduler;
@@ -106,12 +106,12 @@ public void setStompBrokerRelay(StompBrokerRelayMessageHandler stompBrokerRelay)
106106
this.stompBrokerRelay = stompBrokerRelay;
107107
}
108108

109-
public void setInboundChannelExecutor(ThreadPoolTaskExecutor inboundChannelExecutor) {
110-
this.inboundChannelExecutor = inboundChannelExecutor.getThreadPoolExecutor();
109+
public void setInboundChannelExecutor(TaskExecutor inboundChannelExecutor) {
110+
this.inboundChannelExecutor = inboundChannelExecutor;
111111
}
112112

113-
public void setOutboundChannelExecutor(ThreadPoolTaskExecutor outboundChannelExecutor) {
114-
this.outboundChannelExecutor = outboundChannelExecutor.getThreadPoolExecutor();
113+
public void setOutboundChannelExecutor(TaskExecutor outboundChannelExecutor) {
114+
this.outboundChannelExecutor = outboundChannelExecutor;
115115
}
116116

117117
public void setSockJsTaskScheduler(TaskScheduler sockJsTaskScheduler) {
@@ -174,14 +174,16 @@ public String getStompBrokerRelayStatsInfo() {
174174
* Get stats about the executor processing incoming messages from WebSocket clients.
175175
*/
176176
public String getClientInboundExecutorStatsInfo() {
177-
return (this.inboundChannelExecutor != null ? getExecutorStatsInfo(this.inboundChannelExecutor) : "null");
177+
return (this.inboundChannelExecutor != null ?
178+
getExecutorStatsInfo(this.inboundChannelExecutor) : "null");
178179
}
179180

180181
/**
181182
* Get stats about the executor processing outgoing messages to WebSocket clients.
182183
*/
183184
public String getClientOutboundExecutorStatsInfo() {
184-
return (this.outboundChannelExecutor != null ? getExecutorStatsInfo(this.outboundChannelExecutor) : "null");
185+
return (this.outboundChannelExecutor != null ?
186+
getExecutorStatsInfo(this.outboundChannelExecutor) : "null");
185187
}
186188

187189
/**
@@ -201,6 +203,8 @@ public String getSockJsTaskSchedulerStatsInfo() {
201203
}
202204

203205
private String getExecutorStatsInfo(Executor executor) {
206+
executor = executor instanceof ThreadPoolTaskExecutor ?
207+
((ThreadPoolTaskExecutor) executor).getThreadPoolExecutor() : executor;
204208
String str = executor.toString();
205209
return str.substring(str.indexOf("pool"), str.length() - 1);
206210
}

0 commit comments

Comments
 (0)