[Change] ImageCacheStore 优化中断处理, 自动取消任务, 补充TaskState设置;

This commit is contained in:
2020-06-13 12:54:17 +08:00
parent 91f8b0070f
commit 91e065f657

View File

@ -66,17 +66,17 @@ public final class ImageCacheStore {
// 置任务状态
task.taskState.set(TaskState.RUNNING);
Throwable throwable = null;
Future<Throwable> future = imageCacheExecutor.submit(() -> {
try {
handler.getImageToCache(cacheObject);
} catch (Throwable e) {
return e;
}
return null;
});
Throwable throwable;
try {
throwable = imageCacheExecutor.submit(() -> {
try {
handler.getImageToCache(cacheObject);
} catch (Throwable e) {
return e;
}
return null;
}).get();
throwable = future.get();
if(throwable == null) {
task.taskState.set(TaskState.COMPLETE);
} else {
@ -84,6 +84,12 @@ public final class ImageCacheStore {
}
} catch (ExecutionException e) {
log.error("执行图片缓存任务时发生异常", e);
task.taskState.set(TaskState.ERROR);
return e.getCause();
} catch (InterruptedException e) {
future.cancel(true);
task.taskState.set(TaskState.ERROR);
throw e;
}
return throwable;
} finally {