Browse Source

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

xuxueli 7 years ago
parent
commit
e3cce6341b

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

1208
 - 11、任务回调结果优化,支持展示在Rolling log中,方便问题排查;
1208
 - 11、任务回调结果优化,支持展示在Rolling log中,方便问题排查;
1209
 - 12、脚本任务异常Log输出优化;
1209
 - 12、脚本任务异常Log输出优化;
1210
 - 13、任务线程停止变量修饰符优化;
1210
 - 13、任务线程停止变量修饰符优化;
1211
+- 14、脚本任务Log文件流关闭优化;
1211
 
1212
 
1212
 
1213
 
1213
 ### TODO LIST
1214
 ### TODO LIST

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

60
         // 标准输出:print (null if watchdog timeout)
60
         // 标准输出:print (null if watchdog timeout)
61
         // 错误输出:logging + 异常 (still exists if watchdog timeout)
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
             PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
67
             PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null);
65
 
68
 
66
             // command
69
             // command
79
         } catch (Exception e) {
82
         } catch (Exception e) {
80
             XxlJobLogger.log(e);
83
             XxlJobLogger.log(e);
81
             return -1;
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