Browse Source

Use Reactor's new Schedulers.boundedElastic()

Prior to this commit, Spring Framework would use `Schedulers.elastic()`
in places where we needed to process blocking tasks in a reactive
environment.

With reactor/reactor-core#1804, a new `Schedulers.boundedElastic()`
scheduler is available and achieves the same goal with added security;
it guarantees that resources are bounded.

This commit uses that new scheduler in the standard websocket client,
since the underlying API is blocking for the connection phase and we
need to schedule that off a web server thread.

Closes gh-23661
See gh-23665
pull/23772/head
Brian Clozel 6 years ago
parent
commit
74897bc52a
  1. 3
      build.gradle
  2. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/StandardWebSocketClient.java

3
build.gradle

@ -42,7 +42,7 @@ configure(allprojects) { project -> @@ -42,7 +42,7 @@ configure(allprojects) { project ->
imports {
mavenBom "com.fasterxml.jackson:jackson-bom:2.9.9"
mavenBom "io.netty:netty-bom:4.1.39.Final"
mavenBom "io.projectreactor:reactor-bom:Dysprosium-RC1"
mavenBom "io.projectreactor:reactor-bom:Dysprosium-BUILD-SNAPSHOT"
mavenBom "org.eclipse.jetty:jetty-bom:9.4.20.v20190813"
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.3.50"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.3.1"
@ -297,6 +297,7 @@ configure(allprojects) { project -> @@ -297,6 +297,7 @@ configure(allprojects) { project ->
mavenCentral()
maven { url "https://repo.spring.io/libs-release" }
maven { url "https://repo.spring.io/milestone" } // Reactor
maven { url "https://repo.spring.io/snapshot" } // Reactor
}
}
configurations.all {

2
spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/StandardWebSocketClient.java

@ -109,7 +109,7 @@ public class StandardWebSocketClient implements WebSocketClient { @@ -109,7 +109,7 @@ public class StandardWebSocketClient implements WebSocketClient {
ClientEndpointConfig config = createEndpointConfig(configurator, protocols);
return this.webSocketContainer.connectToServer(endpoint, config, url);
})
.subscribeOn(Schedulers.elastic()) // connectToServer is blocking
.subscribeOn(Schedulers.boundedElastic()) // connectToServer is blocking
.then(completionMono);
}

Loading…
Cancel
Save