public void testAwaitTermination_timesOut() throws InterruptedException {
  ForkJoinPool p=new ForkJoinPool(1);
  PoolCleaner cleaner=null;
  try {
    cleaner=cleaner(p);
    assertFalse(p.isTerminated());
    assertFalse(p.awaitTermination(Long.MIN_VALUE,NANOSECONDS));
    assertFalse(p.awaitTermination(Long.MIN_VALUE,MILLISECONDS));
    assertFalse(p.awaitTermination(-1L,NANOSECONDS));
    assertFalse(p.awaitTermination(-1L,MILLISECONDS));
    assertFalse(p.awaitTermination(0L,NANOSECONDS));
    assertFalse(p.awaitTermination(0L,MILLISECONDS));
    long timeoutNanos=999999L;
    long startTime=System.nanoTime();
    assertFalse(p.awaitTermination(timeoutNanos,NANOSECONDS));
    assertTrue(System.nanoTime() - startTime >= timeoutNanos);
    assertFalse(p.isTerminated());
    startTime=System.nanoTime();
    long timeoutMillis=timeoutMillis();
    assertFalse(p.awaitTermination(timeoutMillis,MILLISECONDS));
    assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
    assertFalse(p.isTerminated());
    p.shutdown();
    assertTrue(p.awaitTermination(LONG_DELAY_MS,MILLISECONDS));
    assertTrue(p.isTerminated());
  }
  finally {
    if (cleaner != null) {
      cleaner.close();
    }
  }
}

public void testAwaitTermination_timesOut ( ) throws InterruptedException { ForkJoinPool p = new ForkJoinPool ( 1 ) ; PoolCleaner cleaner = null ; try { cleaner = cleaner ( p ) ; assertFalse ( p . isTerminated ( ) ) ; assertFalse ( p . awaitTermination ( Long . MIN_VALUE , NANOSECONDS ) ) ; assertFalse ( p . awaitTermination ( Long . MIN_VALUE , MILLISECONDS ) ) ; assertFalse ( p . awaitTermination ( - 1L , NANOSECONDS ) ) ; assertFalse ( p . awaitTermination ( - 1L , MILLISECONDS ) ) ; assertFalse ( p . awaitTermination ( 0L , NANOSECONDS ) ) ; assertFalse ( p . awaitTermination ( 0L , MILLISECONDS ) ) ; long timeoutNanos = 999999L ; long startTime = System . nanoTime ( ) ; assertFalse ( p . awaitTermination ( timeoutNanos , NANOSECONDS ) ) ; assertTrue ( System . nanoTime ( ) - startTime >= timeoutNanos ) ; assertFalse ( p . isTerminated ( ) ) ; startTime = System . nanoTime ( ) ; long timeoutMillis = timeoutMillis ( ) ; assertFalse ( p . awaitTermination ( timeoutMillis , MILLISECONDS ) ) ; assertTrue ( millisElapsedSince ( startTime ) >= timeoutMillis ) ; assertFalse ( p . isTerminated ( ) ) ; p . shutdown ( ) ; assertTrue ( p . awaitTermination ( LONG_DELAY_MS , MILLISECONDS ) ) ; assertTrue ( p . isTerminated ( ) ) ; } finally { if ( cleaner != null ) { cleaner . close ( ) ; } } }
awaittermination on a non - shutdown pool times out
