Skip to content

Commit

Permalink
Use Reactor's new Schedulers.boundedElastic()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bclozel committed Sep 18, 2019
1 parent 90b5e6a commit 74897bc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -109,7 +109,7 @@ private Mono<Void> executeInternal(URI url, HttpHeaders requestHeaders, WebSocke
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);
}

Expand Down

0 comments on commit 74897bc

Please sign in to comment.