use of java.util.concurrent.CancellationException in project java-common-lib by sosy-lab.
the class ProcessExecutor method join.
/**
* Wait for the process to terminate.
*
* @param timelimit Maximum time to wait for process (in milliseconds)
* @return The exit code of the process.
* @throws IOException passed from the handle* methods.
* @throws E passed from the handle* methods.
* @throws TimeoutException If timeout is hit.
* @throws InterruptedException If the current thread is interrupted.
*/
public int join(long timelimit) throws IOException, E, TimeoutException, InterruptedException {
try {
@Var Integer exitCode = null;
try {
if (timelimit > 0) {
exitCode = processFuture.get(timelimit, TimeUnit.MILLISECONDS);
} else {
exitCode = processFuture.get();
}
} catch (CancellationException e) {
// the processFuture has been cancelled, probably because the outFuture or
// the errFuture threw an exception
// ignore exception here and call get() on the other futures to get their
// exceptions
}
// wait for reading tasks to finish and to get exceptions
outFuture.get();
errFuture.get();
if (exitCode == null) {
// Assume this as an interrupt.
throw new InterruptedException();
}
return exitCode;
} catch (TimeoutException e) {
logger.log(Level.WARNING, "Killing", name, "due to timeout");
processFuture.cancel(true);
throw e;
} catch (InterruptedException e) {
logger.log(Level.WARNING, "Killing", name, "due to user interrupt");
processFuture.cancel(true);
throw e;
} catch (ExecutionException e) {
Throwable t = e.getCause();
Throwables.propagateIfPossible(t, IOException.class, exceptionClass);
throw new UnexpectedCheckedException("output handling of external process " + name, t);
} finally {
assert processFuture.isDone();
// needed for memory visibility of the Callables
Concurrency.waitForTermination(executor);
try {
in.close();
} catch (IOException e) {
// Not expected to happen because process is already dead anyway.
// Don't hide any real exception by throwing this one.
}
finished = true;
}
}
use of java.util.concurrent.CancellationException in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testJoinIgnoresInterrupts.
/**
* join/quietlyJoin of a forked task succeeds in the presence of interrupts
*/
public void testJoinIgnoresInterrupts() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FibAction f = new FibAction(8);
final Thread currentThread = Thread.currentThread();
// test join()
assertSame(f, f.fork());
currentThread.interrupt();
assertNull(f.join());
Thread.interrupted();
assertEquals(21, f.result);
checkCompletedNormally(f);
f = new FibAction(8);
f.cancel(true);
assertSame(f, f.fork());
currentThread.interrupt();
try {
f.join();
shouldThrow();
} catch (CancellationException success) {
Thread.interrupted();
checkCancelled(f);
}
f = new FibAction(8);
f.completeExceptionally(new FJException());
assertSame(f, f.fork());
currentThread.interrupt();
try {
f.join();
shouldThrow();
} catch (FJException success) {
Thread.interrupted();
checkCompletedAbnormally(f, success);
}
// test quietlyJoin()
f = new FibAction(8);
assertSame(f, f.fork());
currentThread.interrupt();
f.quietlyJoin();
Thread.interrupted();
assertEquals(21, f.result);
checkCompletedNormally(f);
f = new FibAction(8);
f.cancel(true);
assertSame(f, f.fork());
currentThread.interrupt();
f.quietlyJoin();
Thread.interrupted();
checkCancelled(f);
f = new FibAction(8);
f.completeExceptionally(new FJException());
assertSame(f, f.fork());
currentThread.interrupt();
f.quietlyJoin();
Thread.interrupted();
checkCompletedAbnormally(f, f.getException());
}
};
checkInvoke(a);
a.reinitialize();
checkInvoke(a);
}
use of java.util.concurrent.CancellationException in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testCancelledForkGet.
/**
* get of a forked task throws exception when task cancelled
*/
public void testCancelledForkGet() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FibAction f = new FibAction(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.get();
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}
};
checkInvoke(a);
}
use of java.util.concurrent.CancellationException in project streamsupport by stefan-zobel.
the class ForkJoinPool8Test method testCancelledForkTimedGet.
/**
* timed get of a forked task throws exception when task cancelled
*/
public void testCancelledForkTimedGet() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FibAction f = new FibAction(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.get(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}
};
checkInvoke(a);
}
use of java.util.concurrent.CancellationException in project streamsupport by stefan-zobel.
the class RecursiveActionTest method testCancelledForkTimedGet.
/**
* timed get of a forked task throws exception when task cancelled
*/
public void testCancelledForkTimedGet() {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FibAction f = new FibAction(8);
assertTrue(f.cancel(true));
assertSame(f, f.fork());
try {
f.get(LONG_DELAY_MS, MILLISECONDS);
shouldThrow();
} catch (CancellationException success) {
checkCancelled(f);
}
}
};
testInvokeOnPool(mainPool(), a);
}
Aggregations