Evil attempt at ensuring we coax logger to flush

This commit is contained in:
Shane Freeder
2025-11-07 00:08:47 +00:00
parent 81e4e99fbd
commit dcfd25836b

View File

@@ -70,20 +70,31 @@ public class Velocity {
return;
}
final VelocityServer[] velocity = {null};
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if (velocity[0] != null) {
velocity[0].shutdown(true);
} else {
LogManager.shutdown();
}
}, "Shutdown thread"));
long startTime = System.nanoTime();
VelocityServer server = new VelocityServer(options);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false),
"Shutdown thread"));
velocity[0] = new VelocityServer(options);
velocity[0].start();
double bootTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) / 1000d;
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
server.getConsoleCommandSource().start();
velocity[0].getConsoleCommandSource().start();
// If we don't have a console available (because SimpleTerminalConsole returned), then we still
// need to wait, otherwise the JVM will reap us as no non-daemon threads will be active once the
// main thread exits.
server.awaitProxyShutdown();
velocity[0].awaitProxyShutdown();
}
}