Gamelib/src/test/java/uulm/teamname/marvelous/gamelibrary/gamelogic/SimpleErrorSensitiveThreadP...

31 lines
970 B
Java

package uulm.teamname.marvelous.gamelibrary.gamelogic;
import java.util.concurrent.*;
public final class SimpleErrorSensitiveThreadPoolExecutor extends ThreadPoolExecutor {
public SimpleErrorSensitiveThreadPoolExecutor() {
super(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
}
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (t == null && r instanceof Future<?>) {
try {
Future<?> future = (Future<?>) r;
if (future.isDone()) {
future.get();
}
} catch (CancellationException ce) {
t = ce;
} catch (ExecutionException ee) {
t = ee.getCause();
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
}
if (t != null) {
t.printStackTrace();
}
}
}