Add some task test

This commit is contained in:
huanghongxun
2019-02-26 15:28:40 +08:00
parent d9a336e50b
commit 32d0d6a7ee
3 changed files with 45 additions and 4 deletions

View File

@@ -76,6 +76,11 @@ public abstract class Task<T> {
// last exception
private Exception exception;
/**
* When task has been cancelled, task.exception will be null.
*
* @return the exception thrown during execution, possibly from dependents or dependencies.
*/
public final Exception getException() {
return exception;
}

View File

@@ -80,8 +80,10 @@ public final class TaskExecutor {
return future.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException | CancellationException e) {
e.printStackTrace();
} catch (ExecutionException ignore) {
// We have dealt with ExecutionException in exception handling and uncaught exception handler.
} catch (CancellationException e) {
Logging.LOG.log(Level.INFO, "Task " + firstTask + " has been cancelled.", e);
}
return false;
}
@@ -202,8 +204,6 @@ public final class TaskExecutor {
}
task.onDone().fireEvent(new TaskEvent(this, task, true));
taskListeners.forEach(it -> it.onFailed(task, e));
} else if (e instanceof CancellationException || e instanceof RejectedExecutionException) {
task.setException(e);
} else {
task.setException(e);
exception = e;