Skip to content

Commit fb2244b

Browse files
pujaganidiemol
andauthored
Update driver command executor thread executor for driver shutdown (#9430)
* [java] Use fixed thread pool for driver shutdown tasks * [java] Shutdown thread executor service Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent cd64607 commit fb2244b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

java/client/src/org/openqa/selenium/remote/service/DriverCommandExecutor.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
import org.openqa.selenium.remote.HttpCommandExecutor;
2929
import org.openqa.selenium.remote.Response;
3030

31+
import java.io.Closeable;
3132
import java.io.IOException;
3233
import java.net.ConnectException;
3334
import java.util.Map;
3435
import java.util.concurrent.CompletableFuture;
3536
import java.util.concurrent.ExecutionException;
37+
import java.util.concurrent.ExecutorService;
38+
import java.util.concurrent.Executors;
3639
import java.util.concurrent.TimeUnit;
3740
import java.util.concurrent.TimeoutException;
3841

@@ -41,9 +44,15 @@
4144
* and dies with a single WebDriver session. The service will be restarted upon each new session
4245
* request and shutdown after each quit command.
4346
*/
44-
public class DriverCommandExecutor extends HttpCommandExecutor {
47+
public class DriverCommandExecutor extends HttpCommandExecutor implements Closeable {
4548

4649
private final DriverService service;
50+
private final ExecutorService executorService = Executors.newFixedThreadPool(2, r -> {
51+
Thread thread = new Thread(r);
52+
thread.setName("Driver Command Executor");
53+
thread.setDaemon(true);
54+
return thread;
55+
});
4756

4857
/**
4958
* Creates a new DriverCommandExecutor which will communicate with the driver as configured
@@ -104,12 +113,12 @@ public Response execute(Command command) throws IOException {
104113
Throwables.throwIfUnchecked(t);
105114
throw new WebDriverException(t);
106115
}
107-
});
116+
}, executorService);
108117

109118
CompletableFuture<Response> processFinished = CompletableFuture.supplyAsync(() -> {
110119
service.process.waitFor(service.getTimeout().toMillis());
111120
return null;
112-
});
121+
}, executorService);
113122

114123
try {
115124
Response response = (Response) CompletableFuture.anyOf(commandComplete, processFinished)
@@ -152,4 +161,9 @@ public Response execute(Command command) throws IOException {
152161
Response invokeExecute(Command command) throws IOException {
153162
return super.execute(command);
154163
}
164+
165+
@Override
166+
public void close() {
167+
executorService.shutdownNow();
168+
}
155169
}

0 commit comments

Comments
 (0)