Fix #3071: 在 HMCL 被终结时停止日志线程 (#3081)

* update

* update

---------

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
Calboot 2024-05-28 08:17:55 +08:00 committed by GitHub
parent af3719403d
commit 96471e3a92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -111,13 +111,14 @@ public final class Logger {
} }
} }
private void onShutdown() { private void onExit() {
shutdown();
try { try {
loggerThread.join(); loggerThread.join();
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
} }
String caller = CLASS_NAME + ".onShutdown"; String caller = CLASS_NAME + ".onExit";
if (logRetention > 0 && logFile != null) { if (logRetention > 0 && logFile != null) {
List<Pair<Path, int[]>> list = new ArrayList<>(); List<Pair<Path, int[]>> list = new ArrayList<>();
@ -258,7 +259,7 @@ public final class Logger {
loggerThread.setName("HMCL Logger Thread"); loggerThread.setName("HMCL Logger Thread");
loggerThread.start(); loggerThread.start();
Thread cleanerThread = new Thread(this::onShutdown); Thread cleanerThread = new Thread(this::onExit);
cleanerThread.setName("HMCL Logger Shutdown Hook"); cleanerThread.setName("HMCL Logger Shutdown Hook");
Runtime.getRuntime().addShutdownHook(cleanerThread); Runtime.getRuntime().addShutdownHook(cleanerThread);
} }