Sfoglia il codice sorgente

脚本任务Log文件流关闭优化

xuxueli 7 anni fa
parent
commit
e3cce6341b

+ 1 - 0
doc/XXL-JOB官方文档.md Vedi File

@@ -1208,6 +1208,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
1208 1208
 - 11、任务回调结果优化,支持展示在Rolling log中,方便问题排查;
1209 1209
 - 12、脚本任务异常Log输出优化;
1210 1210
 - 13、任务线程停止变量修饰符优化;
1211
+- 14、脚本任务Log文件流关闭优化;
1211 1212
 
1212 1213
 
1213 1214
 ### TODO LIST

+ 13 - 1
xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java Vedi File

@@ -60,7 +60,10 @@ public class ScriptUtil {
60 60
         // 标准输出:print (null if watchdog timeout)
61 61
         // 错误输出:logging + 异常 (still exists if watchdog timeout)
62 62
         // 标准输入
63
-        try (FileOutputStream fileOutputStream = new FileOutputStream(logFile, true)) {
63
+
64
+        FileOutputStream fileOutputStream = null;   //
65
+        try {
66
+            fileOutputStream = new FileOutputStream(logFile, true);
64 67
             PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
65 68
 
66 69
             // command
@@ -79,6 +82,15 @@ public class ScriptUtil {
79 82
         } catch (Exception e) {
80 83
             XxlJobLogger.log(e);
81 84
             return -1;
85
+        } finally {
86
+            if (fileOutputStream != null) {
87
+                try {
88
+                    fileOutputStream.close();
89
+                } catch (IOException e) {
90
+                    XxlJobLogger.log(e);
91
+                }
92
+
93
+            }
82 94
         }
83 95
     }
84 96