Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
abb4474f
authored
Nov 10, 2017
by
anthow
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改JobThread捕获Error错误不更新JobLog
parent
be926f81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
82 deletions
xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java
xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java
View file @
abb4474f
...
@@ -91,86 +91,94 @@ public class JobThread extends Thread{
...
@@ -91,86 +91,94 @@ public class JobThread extends Thread{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
while
(!
toStop
){
running
=
false
;
while
(!
toStop
){
idleTimes
++;
running
=
false
;
try
{
idleTimes
++;
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
// handle job
TriggerParam
triggerParam
=
triggerQueue
.
poll
(
3L
,
TimeUnit
.
SECONDS
);
ReturnT
<
String
>
executeResult
=
null
;
if
(
triggerParam
!=
null
)
{
TriggerParam
triggerParam
=
null
;
running
=
true
;
try
{
idleTimes
=
0
;
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
triggerLogIdSet
.
remove
(
triggerParam
.
getLogId
());
triggerParam
=
triggerQueue
.
poll
(
3L
,
TimeUnit
.
SECONDS
);
if
(
triggerParam
!=
null
)
{
// parse param
running
=
true
;
String
[]
handlerParams
=
(
triggerParam
.
getExecutorParams
()!=
null
&&
triggerParam
.
getExecutorParams
().
trim
().
length
()>
0
)
idleTimes
=
0
;
?
(
String
[])(
Arrays
.
asList
(
triggerParam
.
getExecutorParams
().
split
(
","
)).
toArray
())
:
null
;
triggerLogIdSet
.
remove
(
triggerParam
.
getLogId
());
// handle job
// parse param
ReturnT
<
String
>
executeResult
=
null
;
String
[]
handlerParams
=
(
triggerParam
.
getExecutorParams
()!=
null
&&
triggerParam
.
getExecutorParams
().
trim
().
length
()>
0
)
try
{
?
(
String
[])(
Arrays
.
asList
(
triggerParam
.
getExecutorParams
().
split
(
" "
)).
toArray
())
:
null
;
// log filename: yyyy-MM-dd/9999.log
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
triggerParam
.
getLogDateTim
()),
triggerParam
.
getLogId
());
try
{
XxlJobFileAppender
.
contextHolder
.
set
(
logFileName
);
// log filename: yyyy-MM-dd/9999.log
ShardingUtil
.
setShardingVo
(
new
ShardingUtil
.
ShardingVO
(
triggerParam
.
getBroadcastIndex
(),
triggerParam
.
getBroadcastTotal
()));
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
triggerParam
.
getLogDateTim
()),
triggerParam
.
getLogId
());
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute start -----------<br>----------- Params:"
+
Arrays
.
toString
(
handlerParams
));
XxlJobFileAppender
.
contextHolder
.
set
(
logFileName
);
executeResult
=
handler
.
execute
(
handlerParams
);
ShardingUtil
.
setShardingVo
(
new
ShardingUtil
.
ShardingVO
(
triggerParam
.
getBroadcastIndex
(),
triggerParam
.
getBroadcastTotal
()));
if
(
executeResult
==
null
)
{
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute start -----------<br>----------- Params:"
+
Arrays
.
toString
(
handlerParams
));
executeResult
=
ReturnT
.
FAIL
;
}
executeResult
=
handler
.
execute
(
handlerParams
);
if
(
executeResult
==
null
)
{
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:"
+
executeResult
);
executeResult
=
ReturnT
.
FAIL
;
}
catch
(
Exception
e
)
{
}
if
(
toStop
)
{
XxlJobLogger
.
log
(
"<br>----------- JobThread toStop, stopReason:"
+
stopReason
);
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:"
+
executeResult
);
}
}
catch
(
Exception
e
)
{
if
(
toStop
)
{
StringWriter
stringWriter
=
new
StringWriter
();
XxlJobLogger
.
log
(
"<br>----------- JobThread toStop, stopReason:"
+
stopReason
);
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
}
String
errorMsg
=
stringWriter
.
toString
();
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
StringWriter
stringWriter
=
new
StringWriter
();
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
XxlJobLogger
.
log
(
"<br>----------- JobThread Exception:"
+
errorMsg
+
"<br>----------- xxl-job job execute end(error) -----------"
);
String
errorMsg
=
stringWriter
.
toString
();
}
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
// callback handler info
XxlJobLogger
.
log
(
"<br>----------- JobThread Exception:"
+
errorMsg
+
"<br>----------- xxl-job job execute end(error) -----------"
);
if
(!
toStop
)
{
}
// commonm
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
executeResult
));
}
else
{
}
else
{
if
(
idleTimes
>
30
)
{
// is killed
XxlJobExecutor
.
removeJobThread
(
jobId
,
"excutor idel times over limit."
);
ReturnT
<
String
>
stopResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
stopReason
+
" [业务运行中,被强制终止]"
);
}
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
stopResult
));
}
}
}
catch
(
Throwable
e
)
{
}
else
{
if
(
toStop
)
{
if
(
idleTimes
>
30
)
{
XxlJobLogger
.
log
(
"<br>----------- xxl-job toStop, stopReason:"
+
stopReason
);
XxlJobExecutor
.
removeJobThread
(
jobId
,
"excutor idel times over limit."
);
}
}
}
StringWriter
stringWriter
=
new
StringWriter
();
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
if
(
toStop
)
{
String
errorMsg
=
stringWriter
.
toString
();
XxlJobLogger
.
log
(
"<br>----------- xxl-job toStop, stopReason:"
+
stopReason
);
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
}
XxlJobLogger
.
log
(
"----------- xxl-job JobThread Exception:"
+
errorMsg
);
StringWriter
stringWriter
=
new
StringWriter
();
}
finally
{
e
.
printStackTrace
(
new
PrintWriter
(
stringWriter
));
if
(
triggerParam
!=
null
)
{
String
errorMsg
=
stringWriter
.
toString
();
// callback handler info
XxlJobLogger
.
log
(
"----------- xxl-job JobThread Exception:"
+
errorMsg
);
if
(!
toStop
)
{
}
// commonm
}
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
executeResult
));
}
else
{
// callback trigger request in queue
// is killed
while
(
triggerQueue
!=
null
&&
triggerQueue
.
size
()>
0
){
ReturnT
<
String
>
stopResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
stopReason
+
" [业务运行中,被强制终止]"
);
TriggerParam
triggerParam
=
triggerQueue
.
poll
();
TriggerCallbackThread
.
pushCallBack
(
new
HandleCallbackParam
(
triggerParam
.
getLogId
(),
stopResult
));
if
(
triggerParam
!=
null
)
{
}
// 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
){
logger
.
info
(
">>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}"
,
Thread
.
currentThread
());
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
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment