Selaa lähdekoodia

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

xuxueli 7 vuotta sitten
vanhempi
commit
cf1768d20e

+ 1 - 0
doc/XXL-JOB官方文档.md Näytä tiedosto

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

+ 12 - 14
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java Näytä tiedosto

115
 		appendLog += "\r\n";
115
 		appendLog += "\r\n";
116
 		
116
 		
117
 		// append file content
117
 		// append file content
118
+		FileOutputStream fos = null;
118
 		try {
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
 		} catch (Exception e) {
123
 		} catch (Exception e) {
134
 			logger.error(e.getMessage(), e);
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 Näytä tiedosto

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