Skip to content

Commit 1e6e5ec

Browse files
committed
[java] allow a custom timeout when shutting down a process
1 parent d9f0010 commit 1e6e5ec

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

java/src/org/openqa/selenium/os/ExternalProcess.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.openqa.selenium.os;
1919

20-
import static java.util.concurrent.TimeUnit.SECONDS;
20+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
2121

2222
import java.io.File;
2323
import java.io.IOException;
@@ -269,11 +269,21 @@ public int exitValue() {
269269
* seconds.
270270
*/
271271
public void shutdown() {
272+
shutdown(Duration.ofSeconds(4));
273+
}
274+
275+
/**
276+
* Initiate a normal shutdown of the process or kills it when the process is alive after the given
277+
* timeout.
278+
*
279+
* @param timeout the duration for a process to terminate before destroying it forcibly.
280+
*/
281+
public void shutdown(Duration timeout) {
272282
if (process.supportsNormalTermination()) {
273283
process.destroy();
274284

275285
try {
276-
if (process.waitFor(4, SECONDS)) {
286+
if (process.waitFor(timeout.toMillis(), MILLISECONDS)) {
277287
return;
278288
}
279289
} catch (InterruptedException ex) {

0 commit comments

Comments
 (0)