Skip to content

Commit

Permalink
[java] allow a custom timeout when shutting down a process
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Oct 11, 2023
1 parent d9f0010 commit 1e6e5ec
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions java/src/org/openqa/selenium/os/ExternalProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.openqa.selenium.os;

import static java.util.concurrent.TimeUnit.SECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -269,11 +269,21 @@ public int exitValue() {
* seconds.
*/
public void shutdown() {
shutdown(Duration.ofSeconds(4));
}

/**
* Initiate a normal shutdown of the process or kills it when the process is alive after the given
* timeout.
*
* @param timeout the duration for a process to terminate before destroying it forcibly.
*/
public void shutdown(Duration timeout) {
if (process.supportsNormalTermination()) {
process.destroy();

try {
if (process.waitFor(4, SECONDS)) {
if (process.waitFor(timeout.toMillis(), MILLISECONDS)) {
return;
}
} catch (InterruptedException ex) {
Expand Down

0 comments on commit 1e6e5ec

Please sign in to comment.