Skip to content

Commit

Permalink
修复有时候不会释放锁
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed Jan 24, 2024
1 parent 515069d commit 8ed00d5
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,18 @@ private class updatePlugins extends TimerTask {
boolean c_getPreRelease; // 允许下载预发布版本, 默认 false. 仅限 GitHub

public void run() {
// 防止重复运行
if(lock && !getConfig().getBoolean("disableLook", false)){
log(logLevel.WARN, m.repeatedRunUpdate);
return;
}
lock = true;
logList = new ArrayList<>(); // 清空上一份日志
_startTime = System.nanoTime(); // 记录运行时间
// 新线程
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
// 防止重复运行
if(lock && !getConfig().getBoolean("disableLook", false)){
log(logLevel.WARN, m.repeatedRunUpdate);
return;
}
lock = true;
logList = new ArrayList<>(); // 清空上一份日志
_startTime = System.nanoTime(); // 记录运行时间

log(logLevel.INFO, m.updateStart);

List<?> list = (List<?>) getConfig().get("list");
Expand Down Expand Up @@ -384,16 +385,18 @@ public void run() {

log(logLevel.INFO, " - "+ m.piece(m.updateFulNetRequest, _allRequests) + m.piece(m.updateFulDownloadFile, String.format("%.2f", _allFileSize / 1048576)));

lock = false;

// 运行被推迟的配置重载
if(awaitReload){
awaitReload = false;
loadConfig();
getLogger().info("[AUP] "+ m.logReloadOK);
setTimer();
}
});
}, executor);

// 在任务完成后执行的代码
future.thenRun(() -> lock = false);

executor.shutdown();
}

Expand Down

0 comments on commit 8ed00d5

Please sign in to comment.