fix(DesktopApplication): 优化应用关闭流程以确保线程池正确关闭在处理窗口关闭事件时,调整了资源清理顺序,优先关闭线程池再关闭Spring应用上下文,确保应用能够优雅地释放所有资源并正常退出。
This commit is contained in:
@@ -12,6 +12,7 @@ import javafx.stage.WindowEvent;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DesktopApplication extends Application {
|
||||
@@ -63,10 +64,12 @@ public class DesktopApplication extends Application {
|
||||
}
|
||||
|
||||
private void handleCloseEvent(WindowEvent event) {
|
||||
// 关闭Spring Boot应用上下文
|
||||
closeApplicationContext();
|
||||
// 关闭Playwright实例
|
||||
PlaywrightManager.getInstance().close();
|
||||
// 关闭线程池
|
||||
applicationContext.getBean(ThreadPoolTaskExecutor.class).shutdown();
|
||||
// 关闭Spring Boot应用上下文
|
||||
closeApplicationContext();
|
||||
// 退出JVM
|
||||
Platform.exit();
|
||||
System.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user