Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
X
XXL-JOB
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
靳帅
XXL-JOB
Commits
dd2de9d8
Unverified
提交
dd2de9d8
authored
11月 10, 2017
作者:
许雪里
提交者:
GitHub
11月 10, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #219 from xhanthow/local-job
修改JobThread捕获Error错误不更新JobLog的问题
上级
be926f81
abb4474f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
90 行增加
和
82 行删除
+90
-82
JobThread.java
...core/src/main/java/com/xxl/job/core/thread/JobThread.java
+90
-82
没有找到文件。
xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java
浏览文件 @
dd2de9d8
...
...
@@ -91,86 +91,94 @@ public class JobThread extends Thread{
@Override
public
void
run
()
{
while
(!
toStop
){
running
=
false
;
idleTimes
++;
try
{
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
TriggerParam
triggerParam
=
triggerQueue
.
poll
(
3L
,
TimeUnit
.
SECONDS
);
if
(
triggerParam
!=
null
)
{
running
=
true
;
idleTimes
=
0
;
triggerLogIdSet
.
remove
(
triggerParam
.
getLogId
());
// parse param
String
[]
handlerParams
=
(
triggerParam
.
getExecutorParams
()!=
null
&&
triggerParam
.
getExecutorParams
().
trim
().
length
()>
0
)
?
(
String
[])(
Arrays
.
asList
(
triggerParam
.
getExecutorParams
().
split
(
","
)).
toArray
())
:
null
;
// handle job
ReturnT
<
String
>
executeResult
=
null
;
try
{
// log filename: yyyy-MM-dd/9999.log
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
triggerParam
.
getLogDateTim
()),
triggerParam
.
getLogId
());
XxlJobFileAppender
.
contextHolder
.
set
(
logFileName
);
ShardingUtil
.
setShardingVo
(
new
ShardingUtil
.
ShardingVO
(
triggerParam
.
getBroadcastIndex
(),
triggerParam
.
getBroadcastTotal
()));
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute start -----------<br>----------- Params:"
+
Arrays
.
toString
(
handlerParams
));
executeResult
=
handler
.
execute
(
handlerParams
);
if
(
executeResult
==
null
)
{
executeResult
=
ReturnT
.
FAIL
;
}
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:"
+
executeResult
);
}
catch
(
Exception
e
)
{
if
(
toStop
)
{
XxlJobLogger
.
log
(
"<br>----------- JobThread toStop, stopReason:"
+
stopReason
);
}
StringWriter
stringWriter
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
String
errorMsg
=
stringWriter
.
toString
();
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
XxlJobLogger
.
log
(
"<br>----------- JobThread Exception:"
+
errorMsg
+
"<br>----------- xxl-job job execute end(error) -----------"
);
}
// callback handler info
if
(!
toStop
)
{
// commonm
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
executeResult
));
}
else
{
// is killed
ReturnT
<
String
>
stopResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
stopReason
+
" [业务运行中,被强制终止]"
);
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
stopResult
));
}
}
else
{
if
(
idleTimes
>
30
)
{
XxlJobExecutor
.
removeJobThread
(
jobId
,
"excutor idel times over limit."
);
}
}
}
catch
(
Throwable
e
)
{
if
(
toStop
)
{
XxlJobLogger
.
log
(
"<br>----------- xxl-job toStop, stopReason:"
+
stopReason
);
}
StringWriter
stringWriter
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
String
errorMsg
=
stringWriter
.
toString
();
XxlJobLogger
.
log
(
"----------- xxl-job JobThread Exception:"
+
errorMsg
);
}
}
// callback trigger request in queue
while
(
triggerQueue
!=
null
&&
triggerQueue
.
size
()>
0
){
TriggerParam
triggerParam
=
triggerQueue
.
poll
();
if
(
triggerParam
!=
null
)
{
// is killed
ReturnT
<
String
>
stopResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
stopReason
+
" [任务尚未执行,在调度队列中被终止]"
);
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
stopResult
));
}
}
logger
.
info
(
">>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}"
,
Thread
.
currentThread
());
}
while
(!
toStop
){
running
=
false
;
idleTimes
++;
// handle job
ReturnT
<
String
>
executeResult
=
null
;
TriggerParam
triggerParam
=
null
;
try
{
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
triggerParam
=
triggerQueue
.
poll
(
3L
,
TimeUnit
.
SECONDS
);
if
(
triggerParam
!=
null
)
{
running
=
true
;
idleTimes
=
0
;
triggerLogIdSet
.
remove
(
triggerParam
.
getLogId
());
// parse param
String
[]
handlerParams
=
(
triggerParam
.
getExecutorParams
()!=
null
&&
triggerParam
.
getExecutorParams
().
trim
().
length
()>
0
)
?
(
String
[])(
Arrays
.
asList
(
triggerParam
.
getExecutorParams
().
split
(
" "
)).
toArray
())
:
null
;
try
{
// log filename: yyyy-MM-dd/9999.log
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
triggerParam
.
getLogDateTim
()),
triggerParam
.
getLogId
());
XxlJobFileAppender
.
contextHolder
.
set
(
logFileName
);
ShardingUtil
.
setShardingVo
(
new
ShardingUtil
.
ShardingVO
(
triggerParam
.
getBroadcastIndex
(),
triggerParam
.
getBroadcastTotal
()));
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute start -----------<br>----------- Params:"
+
Arrays
.
toString
(
handlerParams
));
executeResult
=
handler
.
execute
(
handlerParams
);
if
(
executeResult
==
null
)
{
executeResult
=
ReturnT
.
FAIL
;
}
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:"
+
executeResult
);
}
catch
(
Exception
e
)
{
if
(
toStop
)
{
XxlJobLogger
.
log
(
"<br>----------- JobThread toStop, stopReason:"
+
stopReason
);
}
StringWriter
stringWriter
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
String
errorMsg
=
stringWriter
.
toString
();
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
XxlJobLogger
.
log
(
"<br>----------- JobThread Exception:"
+
errorMsg
+
"<br>----------- xxl-job job execute end(error) -----------"
);
}
}
else
{
if
(
idleTimes
>
30
)
{
XxlJobExecutor
.
removeJobThread
(
jobId
,
"excutor idel times over limit."
);
}
}
}
catch
(
Throwable
e
)
{
if
(
toStop
)
{
XxlJobLogger
.
log
(
"<br>----------- xxl-job toStop, stopReason:"
+
stopReason
);
}
StringWriter
stringWriter
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
String
errorMsg
=
stringWriter
.
toString
();
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
XxlJobLogger
.
log
(
"----------- xxl-job JobThread Exception:"
+
errorMsg
);
}
finally
{
if
(
triggerParam
!=
null
)
{
// callback handler info
if
(!
toStop
)
{
// commonm
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
executeResult
));
}
else
{
// is killed
ReturnT
<
String
>
stopResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
stopReason
+
" [业务运行中,被强制终止]"
);
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
stopResult
));
}
}
}
}
// callback trigger request in queue
while
(
triggerQueue
!=
null
&&
triggerQueue
.
size
()>
0
){
TriggerParam
triggerParam
=
triggerQueue
.
poll
();
if
(
triggerParam
!=
null
)
{
// is killed
ReturnT
<
String
>
stopResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
stopReason
+
" [任务尚未执行,在调度队列中被终止]"
);
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
stopResult
));
}
}
logger
.
info
(
">>>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}"
,
Thread
.
currentThread
());
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论