8064932: java/lang/ProcessBuilder/Basic.java: waitFor didn't take long enough
Reviewed-by: dholmes, martin
This commit is contained in:
parent
477b157f38
commit
53906a2cb4
@ -406,14 +406,17 @@ final class UNIXProcess extends Process {
|
|||||||
if (hasExited) return true;
|
if (hasExited) return true;
|
||||||
if (timeout <= 0) return false;
|
if (timeout <= 0) return false;
|
||||||
|
|
||||||
long timeoutAsNanos = unit.toNanos(timeout);
|
long remainingNanos = unit.toNanos(timeout);
|
||||||
long startTime = System.nanoTime();
|
long deadline = System.nanoTime() + remainingNanos;
|
||||||
long rem = timeoutAsNanos;
|
|
||||||
|
|
||||||
while (!hasExited && (rem > 0)) {
|
do {
|
||||||
wait(Math.max(TimeUnit.NANOSECONDS.toMillis(rem), 1));
|
// Round up to next millisecond
|
||||||
rem = timeoutAsNanos - (System.nanoTime() - startTime);
|
wait(TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L));
|
||||||
}
|
if (hasExited) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
remainingNanos = deadline - System.nanoTime();
|
||||||
|
} while (remainingNanos > 0);
|
||||||
return hasExited;
|
return hasExited;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,11 +461,21 @@ final class ProcessImpl extends Process {
|
|||||||
if (getExitCodeProcess(handle) != STILL_ACTIVE) return true;
|
if (getExitCodeProcess(handle) != STILL_ACTIVE) return true;
|
||||||
if (timeout <= 0) return false;
|
if (timeout <= 0) return false;
|
||||||
|
|
||||||
long msTimeout = unit.toMillis(timeout);
|
long remainingNanos = unit.toNanos(timeout);
|
||||||
|
long deadline = System.nanoTime() + remainingNanos ;
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Round up to next millisecond
|
||||||
|
long msTimeout = TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L);
|
||||||
|
waitForTimeoutInterruptibly(handle, msTimeout);
|
||||||
|
if (Thread.interrupted())
|
||||||
|
throw new InterruptedException();
|
||||||
|
if (getExitCodeProcess(handle) != STILL_ACTIVE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
remainingNanos = deadline - System.nanoTime();
|
||||||
|
} while (remainingNanos > 0);
|
||||||
|
|
||||||
waitForTimeoutInterruptibly(handle, msTimeout);
|
|
||||||
if (Thread.interrupted())
|
|
||||||
throw new InterruptedException();
|
|
||||||
return (getExitCodeProcess(handle) != STILL_ACTIVE);
|
return (getExitCodeProcess(handle) != STILL_ACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user