459 throws InterruptedException |
459 throws InterruptedException |
460 { |
460 { |
461 if (getExitCodeProcess(handle) != STILL_ACTIVE) return true; |
461 if (getExitCodeProcess(handle) != STILL_ACTIVE) return true; |
462 if (timeout <= 0) return false; |
462 if (timeout <= 0) return false; |
463 |
463 |
464 long msTimeout = unit.toMillis(timeout); |
464 long remainingNanos = unit.toNanos(timeout); |
465 |
465 long deadline = System.nanoTime() + remainingNanos ; |
466 waitForTimeoutInterruptibly(handle, msTimeout); |
466 |
467 if (Thread.interrupted()) |
467 do { |
468 throw new InterruptedException(); |
468 // Round up to next millisecond |
|
469 long msTimeout = TimeUnit.NANOSECONDS.toMillis(remainingNanos + 999_999L); |
|
470 waitForTimeoutInterruptibly(handle, msTimeout); |
|
471 if (Thread.interrupted()) |
|
472 throw new InterruptedException(); |
|
473 if (getExitCodeProcess(handle) != STILL_ACTIVE) { |
|
474 return true; |
|
475 } |
|
476 remainingNanos = deadline - System.nanoTime(); |
|
477 } while (remainingNanos > 0); |
|
478 |
469 return (getExitCodeProcess(handle) != STILL_ACTIVE); |
479 return (getExitCodeProcess(handle) != STILL_ACTIVE); |
470 } |
480 } |
471 |
481 |
472 private static native void waitForTimeoutInterruptibly( |
482 private static native void waitForTimeoutInterruptibly( |
473 long handle, long timeout); |
483 long handle, long timeout); |