Details
Description
Summary
Provide an overload method for java.lang.Process#waitFor()
that takes a java.time.Duration
for its timeout value
Problem
There is already a waitFor()
method that takes a timeout, but it consists of a primitive long
value and its unit in TimeUnit
. Users sometimes make mistakes with the unit, which results in unexpected behavior.
Solution
Introduce a new overload method waitFor(Duration)
.
Specification
Add the following new method in java.lang.Process
class:
+ /**
+ * Causes the current thread to wait, if necessary, until the
+ * process represented by this {@code Process} object has
+ * terminated, or the specified waiting duration elapses.
+ *
+ * <p>If the process has already terminated then this method returns
+ * immediately with the value {@code true}. If the process has not
+ * terminated and the duration is not positive, then
+ * this method returns immediately with the value {@code false}.
+ *
+ * <p>The default implementation of this method polls the {@code exitValue}
+ * to check if the process has terminated. Concrete implementations of this
+ * class are strongly encouraged to override this method with a more
+ * efficient implementation.
+ *
+ * @param duration the maximum duration to wait; if not positive,
+ * this method returns immediately.
+ * @return {@code true} if the process has exited and {@code false} if
+ * the waiting duration elapsed before the process has exited.
+ * @throws InterruptedException if the current thread is interrupted
+ * while waiting.
+ * @throws NullPointerException if duration is null
+ * @since 24
+ */
+ public boolean waitFor(Duration duration)
+ throws InterruptedException
Attachments
Issue Links
- csr of
-
JDK-8336479 Provide Process.waitFor(Duration)
- Resolved