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

@ -171,6 +171,8 @@ public final class Controllers {
}
public static void showUpdate() {
if (stage == null) // shut down
return;
getLeftPaneController().showUpdate();
}

View File

@ -22,6 +22,8 @@ import org.jackhuang.hmcl.Launcher;
import org.jackhuang.hmcl.event.Event;
import org.jackhuang.hmcl.event.EventBus;
import org.jackhuang.hmcl.event.OutOfDateEvent;
import org.jackhuang.hmcl.task.GetTask;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskResult;
import org.jackhuang.hmcl.ui.construct.MessageBox;
import org.jackhuang.hmcl.util.Constants;
@ -30,6 +32,8 @@ import org.jackhuang.hmcl.util.NetworkUtils;
import org.jackhuang.hmcl.util.VersionNumber;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Level;
@ -65,13 +69,20 @@ public final class UpdateChecker {
*/
public TaskResult<VersionNumber> process(final boolean showMessage) {
return new TaskResult<VersionNumber>() {
GetTask http = new GetTask(NetworkUtils.toURL("https://huangyuhui.duapp.com/hmcl/update.php?version=" + Launcher.VERSION));
@Override
public Collection<? extends Task> getDependents() {
return value == null ? Collections.singleton(http) : Collections.emptyList();
}
@Override
public void execute() throws Exception {
if (Launcher.VERSION.contains("@"))
return;
if (value == null) {
versionString = NetworkUtils.doGet(NetworkUtils.toURL("https://huangyuhui.duapp.com/hmcl/update.php?version=" + Launcher.VERSION));
versionString = http.getResult();
value = VersionNumber.asVersion(versionString);
}

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);
}
}
}