0

I have a block of code, while executing code it will generate popup window, if we click manually then it will process, because of that it is waiting long time, I Would like to introduce timeout function here, can suggest please?

try {
        Process process = Runtime.getRuntime();
        process.waitFor(); //need to introduce Timeout here.
        returnValue = process.exitValue();
        if (returnValue != -1) {
        return true;
        }
    } catch (Exception e) {
        System.out.println(e);
        return false;

if didnt get response within time frame then forget it, and it should return false.

Francesco
  • 897
  • 8
  • 22
Nanu
  • 19
  • 5

1 Answers1

4

Use Process.waitFor(long,TimeUnit).

Causes the current thread to wait, if necessary, until the subprocess represented by this Process object has terminated, or the specified waiting time elapses.

Andy Turner
  • 137,514
  • 11
  • 162
  • 243
  • If add process.waitFor(long, TimeUnit) getting an compilation error like, Undefined reference: boolean Process.waitFor(long, TimeUnit) ; Failed to execute Goal: animal-sniffer-maven-plugin – Nanu May 07 '20 at 14:17