Shutdown Now to prevent NPE when task executed after app closed

This commit is contained in:
huangyuhui
2018-06-06 23:52:23 +08:00
parent 2575f10497
commit a9261b759b
5 changed files with 26 additions and 5 deletions

View File

@@ -172,6 +172,12 @@ public class DefaultGameRepository implements GameRepository {
if (files != null)
for (File dir : files)
if (dir.isDirectory()) {
if (Thread.interrupted()) {
this.versions = new HashMap<>();
loaded = false;
return;
}
String id = dir.getName();
File json = new File(dir, id + ".json");

View File

@@ -119,12 +119,12 @@ public final class Schedulers {
Logging.LOG.info("Shutting down executor services.");
if (CACHED_EXECUTOR != null)
CACHED_EXECUTOR.shutdown();
CACHED_EXECUTOR.shutdownNow();
if (IO_EXECUTOR != null)
IO_EXECUTOR.shutdown();
IO_EXECUTOR.shutdownNow();
if (SINGLE_EXECUTOR != null)
SINGLE_EXECUTOR.shutdown();
SINGLE_EXECUTOR.shutdownNow();
}
}

View File

@@ -89,8 +89,10 @@ public final class TaskExecutor {
while (!workerQueue.isEmpty()) {
Future<?> future = workerQueue.poll();
if (future != null)
if (future != null) {
future.cancel(true);
System.out.println("Canceled " + future);
}
}
}