Skip to content

Commit 007a347

Browse files
committed
Refine executor description in WebSocketMessageBrokerStats
Closes gh-33104
1 parent bd31e8d commit 007a347

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.core.task.TaskExecutor;
3131
import org.springframework.lang.Nullable;
3232
import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler;
33+
import org.springframework.scheduling.SchedulingTaskExecutor;
3334
import org.springframework.scheduling.TaskScheduler;
3435
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
3536
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -239,9 +240,15 @@ public String getSockJsTaskSchedulerStatsInfo() {
239240
if (this.sockJsTaskScheduler == null) {
240241
return "null";
241242
}
242-
if (this.sockJsTaskScheduler instanceof ThreadPoolTaskScheduler threadPoolTaskScheduler) {
243-
return getExecutorStatsInfo(threadPoolTaskScheduler.getScheduledThreadPoolExecutor());
243+
244+
if (!(this.sockJsTaskScheduler instanceof SchedulingTaskExecutor)) {
245+
return "thread-per-task";
246+
}
247+
248+
if (this.sockJsTaskScheduler instanceof ThreadPoolTaskScheduler tpts) {
249+
return getExecutorStatsInfo(tpts.getScheduledThreadPoolExecutor());
244250
}
251+
245252
return "unknown";
246253
}
247254

@@ -250,8 +257,12 @@ private String getExecutorStatsInfo(@Nullable Executor executor) {
250257
return "null";
251258
}
252259

253-
if (executor instanceof ThreadPoolTaskExecutor threadPoolTaskScheduler) {
254-
executor = threadPoolTaskScheduler.getThreadPoolExecutor();
260+
if (!(executor instanceof SchedulingTaskExecutor) && (executor instanceof TaskExecutor)) {
261+
return "thread-per-task";
262+
}
263+
264+
if (executor instanceof ThreadPoolTaskExecutor tpte) {
265+
executor = tpte.getThreadPoolExecutor();
255266
}
256267

257268
if (executor instanceof ThreadPoolExecutor) {

spring-websocket/src/test/java/org/springframework/web/socket/config/WebSocketMessageBrokerStatsTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ void inboundAndOutboundChannelsWithMockedTaskExecutor() {
6565
stats.setInboundChannelExecutor(executor);
6666
stats.setOutboundChannelExecutor(executor);
6767

68-
assertThat(stats.getClientInboundExecutorStatsInfo()).as("inbound channel stats").isEqualTo("unknown");
69-
assertThat(stats.getClientOutboundExecutorStatsInfo()).as("outbound channel stats").isEqualTo("unknown");
68+
assertThat(stats.getClientInboundExecutorStatsInfo()).as("inbound channel stats").isEqualTo("thread-per-task");
69+
assertThat(stats.getClientOutboundExecutorStatsInfo()).as("outbound channel stats").isEqualTo("thread-per-task");
7070
}
7171

7272
@Test
@@ -86,7 +86,7 @@ void sockJsTaskSchedulerWithMockedTaskScheduler() {
8686

8787
stats.setSockJsTaskScheduler(scheduler);
8888

89-
assertThat(stats.getSockJsTaskSchedulerStatsInfo()).isEqualTo("unknown");
89+
assertThat(stats.getSockJsTaskSchedulerStatsInfo()).isEqualTo("thread-per-task");
9090
}
9191

9292
}

0 commit comments

Comments
 (0)