diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java index aa99dcce84..18f1481d7c 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/WebSocketNamespaceUtils.java @@ -138,6 +138,7 @@ class WebSocketNamespaceUtils { RootBeanDefinition taskSchedulerDef = new RootBeanDefinition(ThreadPoolTaskScheduler.class); taskSchedulerDef.setSource(source); taskSchedulerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + taskSchedulerDef.getPropertyValues().add("poolSize", Runtime.getRuntime().availableProcessors()); taskSchedulerDef.getPropertyValues().add("threadNamePrefix", schedulerName + "-"); parserContext.getRegistry().registerBeanDefinition(schedulerName, taskSchedulerDef); parserContext.registerComponent(new BeanComponentDefinition(taskSchedulerDef, schedulerName)); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java index f73f598b4f..632fe34101 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java @@ -46,6 +46,7 @@ import org.springframework.messaging.simp.user.UserSessionRegistry; import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler; import org.springframework.messaging.support.AbstractSubscribableChannel; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.util.MimeTypeUtils; import org.springframework.web.HttpRequestHandler; import org.springframework.web.context.support.GenericWebApplicationContext; @@ -134,6 +135,9 @@ public class MessageBrokerBeanDefinitionParserTests { assertNotNull(wsTransportHandler.getHandshakeHandler()); assertThat(wsTransportHandler.getHandshakeHandler(), Matchers.instanceOf(TestHandshakeHandler.class)); + ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler) defaultSockJsService.getTaskScheduler(); + assertEquals(Runtime.getRuntime().availableProcessors(), scheduler.getScheduledThreadPoolExecutor().getCorePoolSize()); + UserSessionRegistry userSessionRegistry = this.appContext.getBean(UserSessionRegistry.class); assertNotNull(userSessionRegistry); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java index 3634990b36..16d64a0577 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java @@ -37,6 +37,7 @@ import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.simp.annotation.SubscribeMapping; import org.springframework.messaging.simp.stomp.StompCommand; import org.springframework.messaging.simp.stomp.StompHeaderAccessor; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Controller; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; @@ -122,6 +123,15 @@ public class WebSocketMessageBrokerConfigurationSupportTests { } } + @Test + public void messageBrokerSockJsTaskScheduler() { + ThreadPoolTaskScheduler taskScheduler = + this.config.getBean("messageBrokerSockJsTaskScheduler", ThreadPoolTaskScheduler.class); + + assertEquals(Runtime.getRuntime().availableProcessors(), + taskScheduler.getScheduledThreadPoolExecutor().getCorePoolSize()); + } + @Controller static class TestController { diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java index 8559b5a86b..756a86eda9 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompWebSocketIntegrationTests.java @@ -85,7 +85,7 @@ public class StompWebSocketIntegrationTests extends AbstractWebSocketIntegration SimpleController controller = this.wac.getBean(SimpleController.class); try { - assertTrue(controller.latch.await(2, TimeUnit.SECONDS)); + assertTrue(controller.latch.await(10, TimeUnit.SECONDS)); } finally { session.close();