ProcessHandle::onExit behavior

Sander Mak sander.mak at
Mon Mar 6 15:46:06 UTC 2017

I was trying to get an example to work with the new ProcessHandle API. My goal was to wait on another process (Spotify) to terminate before printing something to the console:

ProcessHandle handle =
          .filter(h -> -> cmd.contains("Spotify")).orElse(false))
        .orElseThrow(() -> new IllegalArgumentException("No matching handle found"));


ProcessHandle completed = handle.onExit().get();

However this code doesn't wait on `handle` to be terminated, as the JavaDoc of onExit led me to believe: "Calling onExit().get() waits for the process to terminate and returns the ProcessHandle.". What I expected: the get() call blocks until I terminate the Spotify process. Instead, it runs to completion and prints true for the `isAlive` call in the end.  Am I missing something?

Env: Java(TM) SE Runtime Environment (build 9-ea+157-jigsaw-nightly-h6122-20170221) on MacOS.

Also, first time posting to this list, I hope this is the right avenue for these questions.


More information about the core-libs-dev mailing list