Skip to content

Commit

Permalink
[java] use daemon threads in JdkHttpClient #13601
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Feb 23, 2024
1 parent 93c7804 commit ddaa4aa
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -69,6 +70,7 @@

public class JdkHttpClient implements HttpClient {
public static final Logger LOG = Logger.getLogger(JdkHttpClient.class.getName());
private static final AtomicInteger POOL_COUNTER = new AtomicInteger(0);
private final JdkHttpMessages messages;
private final HttpHandler handler;
private java.net.http.HttpClient client;
Expand All @@ -84,7 +86,15 @@ public class JdkHttpClient implements HttpClient {
this.websockets = new ArrayList<>();
this.handler = config.filter().andFinally(this::execute0);

executorService = Executors.newCachedThreadPool();
String poolName = "JdkHttpClient-" + POOL_COUNTER.getAndIncrement();
AtomicInteger threadCounter = new AtomicInteger(0);
executorService =
Executors.newCachedThreadPool(
r -> {
Thread thread = new Thread(r, poolName + "-" + threadCounter.getAndIncrement());
thread.setDaemon(true);
return thread;
});

java.net.http.HttpClient.Builder builder =
java.net.http.HttpClient.newBuilder()
Expand Down

0 comments on commit ddaa4aa

Please sign in to comment.