浏览代码

Merge branch 'master' of https://github.com/xuxueli/xxl-job

xuxueli 7 年前
父节点
当前提交
cf1768d20e

+ 1 - 0
doc/XXL-JOB官方文档.md 查看文件

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

+ 12 - 14
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java 查看文件

@@ -115,23 +115,21 @@ public class XxlJobFileAppender {
115 115
 		appendLog += "\r\n";
116 116
 		
117 117
 		// append file content
118
+		FileOutputStream fos = null;
118 119
 		try {
119
-			FileOutputStream fos = null;
120
-			try {
121
-				fos = new FileOutputStream(logFile, true);
122
-				fos.write(appendLog.getBytes("utf-8"));
123
-				fos.flush();
124
-			} finally {
125
-				if (fos != null) {
126
-					try {
127
-						fos.close();
128
-					} catch (IOException e) {
129
-						logger.error(e.getMessage(), e);
130
-					}
131
-				}
132
-			} 
120
+			fos = new FileOutputStream(logFile, true);
121
+			fos.write(appendLog.getBytes("utf-8"));
122
+			fos.flush();
133 123
 		} catch (Exception e) {
134 124
 			logger.error(e.getMessage(), e);
125
+		} finally {
126
+			if (fos != null) {
127
+				try {
128
+					fos.close();
129
+				} catch (IOException e) {
130
+					logger.error(e.getMessage(), e);
131
+				}
132
+			}
135 133
 		}
136 134
 		
137 135
 	}

+ 13 - 1
xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java 查看文件

@@ -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