Skip to content

Commit 82a7d0a

Browse files
committed
Migration to virtual threads - phase 3
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
1 parent 4fb19e3 commit 82a7d0a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/groovy/io/seqera/wave/http/HttpClientFactory.groovy

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ package io.seqera.wave.http
2020

2121
import java.net.http.HttpClient
2222
import java.time.Duration
23-
import java.util.concurrent.ExecutorService
2423
import java.util.concurrent.Executors
24+
import java.util.concurrent.ThreadFactory
2525
import java.util.concurrent.locks.ReentrantLock
2626

2727
import groovy.transform.CompileStatic
2828
import groovy.util.logging.Slf4j
29-
import io.seqera.wave.util.CustomThreadFactory
3029
/**
3130
* Java HttpClient factory
3231
*
@@ -36,7 +35,9 @@ import io.seqera.wave.util.CustomThreadFactory
3635
@CompileStatic
3736
class HttpClientFactory {
3837

39-
static private ExecutorService threadPool = Executors.newCachedThreadPool(new CustomThreadFactory("HttpClientThread"))
38+
static final private ThreadFactory customThreadFactory = Thread.ofVirtual()
39+
.name("httpclient-virtual-thread-", 1)
40+
.factory();
4041

4142
static private Duration timeout = Duration.ofSeconds(20)
4243

@@ -84,7 +85,7 @@ class HttpClientFactory {
8485
.version(HttpClient.Version.HTTP_1_1)
8586
.followRedirects(HttpClient.Redirect.NORMAL)
8687
.connectTimeout(timeout)
87-
.executor(threadPool)
88+
.executor(Executors.newThreadPerTaskExecutor(customThreadFactory))
8889
.build()
8990
log.debug "Creating new followRedirectsHttpClient: $result"
9091
return result
@@ -95,7 +96,7 @@ class HttpClientFactory {
9596
.version(HttpClient.Version.HTTP_1_1)
9697
.followRedirects(HttpClient.Redirect.NEVER)
9798
.connectTimeout(timeout)
98-
.executor(threadPool)
99+
.executor(Executors.newThreadPerTaskExecutor(customThreadFactory))
99100
.build()
100101
log.debug "Creating new neverRedirectsHttpClient: $result"
101102
return result

0 commit comments

Comments
 (0)