[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); task.taskState.set(TaskState.RUNNING);
Throwable throwable = null; Future<Throwable> future = imageCacheExecutor.submit(() -> {
try {
throwable = imageCacheExecutor.submit(() -> {
try { try {
handler.getImageToCache(cacheObject); handler.getImageToCache(cacheObject);
} catch (Throwable e) { } catch (Throwable e) {
return e; return e;
} }
return null; return null;
}).get(); });
Throwable throwable;
try {
throwable = future.get();
if(throwable == null) { if(throwable == null) {
task.taskState.set(TaskState.COMPLETE); task.taskState.set(TaskState.COMPLETE);
} else { } else {
@ -84,6 +84,12 @@ public final class ImageCacheStore {
} }
} catch (ExecutionException e) { } catch (ExecutionException e) {
log.error("执行图片缓存任务时发生异常", 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; return throwable;
} finally { } finally {