diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java index a0c57282ed1..37f5b917570 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java @@ -84,12 +84,14 @@ public class WebSocketConfigurationSupport { @Bean @Nullable public TaskScheduler defaultSockJsTaskScheduler() { - if (initHandlerRegistry().requiresTaskScheduler()) { - ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler(); - threadPoolScheduler.setThreadNamePrefix("SockJS-"); - threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors()); - threadPoolScheduler.setRemoveOnCancelPolicy(true); - this.scheduler = threadPoolScheduler; + if (this.scheduler == null) { + if (initHandlerRegistry().requiresTaskScheduler()) { + ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler(); + threadPoolScheduler.setThreadNamePrefix("SockJS-"); + threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors()); + threadPoolScheduler.setRemoveOnCancelPolicy(true); + this.scheduler = threadPoolScheduler; + } } return this.scheduler; }