Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8336494

Provide Process.waitFor(Duration)

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 24
    • core-libs
    • None
    • source
    • minimal
    • This is a new method, thus no backward compatibility is expected. Existing user subclasses might have accidentally overridden this method.
    • Java API
    • SE

    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

          Activity

            People

              naoto Naoto Sato
              prappo Pavel Rappo
              Chen Liang, Pavel Rappo, Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: