From 007bdede4693332eb9fb857085fd87c389c3ebfa Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Mon, 4 Jul 2022 16:17:57 +0100 Subject: [PATCH] Add missing check to avoid re-initialization Noticed during review of #28736 that a check protecting against re-initialization was accidentally removed in commit 3d6e38bb43fe86cc58bc816eff13b968c1e0884f. --- .../annotation/WebSocketConfigurationSupport.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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; }