Selaa lähdekoodia

# feat:增加退出时释放资源的方法;每次处理完显示清理不需要的对象;

yang yi 6 kuukautta sitten
vanhempi
sitoutus
017957ca13
1 muutettua tiedostoa jossa 17 lisäystä ja 3 poistoa
  1. 17 3
      src/main/java/space/anyi/amountVerification/App.java

+ 17 - 3
src/main/java/space/anyi/amountVerification/App.java

@@ -121,7 +121,7 @@ public class App extends Application {
         // 设置窗口关闭事件处理
         primaryStage.setOnCloseRequest(event -> {
             event.consume(); // 阻止默认关闭行为
-            showCloseConfirmation(primaryStage);
+            showCloseConfirmation();
         });
 
         // 创建主布局
@@ -194,6 +194,14 @@ public class App extends Application {
         primaryStage.show();
     }
 
+    /**
+     * 程序退出方法
+     * 可以在这里释放资源
+     */
+    public void exit(){
+        this.primaryStage.close();
+    }
+
     private MenuBar createMenuBar() {
         MenuBar menuBar = new MenuBar();
 
@@ -222,7 +230,7 @@ public class App extends Application {
         alert.showAndWait();
     }
 
-    private void showCloseConfirmation(Stage stage) {
+    private void showCloseConfirmation() {
         Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
         alert.setTitle("确认关闭");
         alert.setHeaderText("您确定要关闭应用程序吗?");
@@ -230,7 +238,7 @@ public class App extends Application {
 
         Optional<ButtonType> result = alert.showAndWait();
         if (result.isPresent() && result.get() == ButtonType.OK) {
-            stage.close();
+            exit();
         }
     }
 
@@ -335,6 +343,8 @@ public class App extends Application {
                             (errorImeiList.isEmpty() ? "" : "\n\nIMEI处理失败数量: " + errorImeiList.size()));
                     alert.showAndWait();
                 });
+            } catch (Exception e) {
+                log.error("验证失败", e);
             } finally {
                 // 隐藏进度条
                 progressBar.setVisible(false);
@@ -345,9 +355,13 @@ public class App extends Application {
                 fileField.clear();
                 folderField.clear();
                 //资源清理
+                inputModelList.clear();
                 inputModelList = null;
+                outputModelList.clear();
                 outputModelList = null;
+                workOrderFileMap.clear();
                 workOrderFileMap = null;
+                System.gc();
             }
         });
         thread.setDaemon(true);