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
449691d3
authored
Nov 10, 2017
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
任务线程Error异常逻辑逻辑优化
parent
dd2de9d8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
22 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 @
449691d3
...
@@ -95,9 +95,9 @@ public class JobThread extends Thread{
...
@@ -95,9 +95,9 @@ public class JobThread extends Thread{
while
(!
toStop
){
while
(!
toStop
){
running
=
false
;
running
=
false
;
idleTimes
++;
idleTimes
++;
// handle job
ReturnT
<
String
>
executeResult
=
null
;
TriggerParam
triggerParam
=
null
;
TriggerParam
triggerParam
=
null
;
ReturnT
<
String
>
executeResult
=
null
;
try
{
try
{
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
triggerParam
=
triggerQueue
.
poll
(
3L
,
TimeUnit
.
SECONDS
);
triggerParam
=
triggerQueue
.
poll
(
3L
,
TimeUnit
.
SECONDS
);
...
@@ -108,35 +108,21 @@ public class JobThread extends Thread{
...
@@ -108,35 +108,21 @@ public class JobThread extends Thread{
// parse param
// parse param
String
[]
handlerParams
=
(
triggerParam
.
getExecutorParams
()!=
null
&&
triggerParam
.
getExecutorParams
().
trim
().
length
()>
0
)
String
[]
handlerParams
=
(
triggerParam
.
getExecutorParams
()!=
null
&&
triggerParam
.
getExecutorParams
().
trim
().
length
()>
0
)
?
(
String
[])(
Arrays
.
asList
(
triggerParam
.
getExecutorParams
().
split
(
"
"
)).
toArray
())
:
null
;
?
(
String
[])(
Arrays
.
asList
(
triggerParam
.
getExecutorParams
().
split
(
",
"
)).
toArray
())
:
null
;
try
{
// log filename: yyyy-MM-dd/9999.log
// log filename: yyyy-MM-dd/9999.log
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
triggerParam
.
getLogDateTim
()),
triggerParam
.
getLogId
());
String
logFileName
=
XxlJobFileAppender
.
makeLogFileName
(
new
Date
(
triggerParam
.
getLogDateTim
()),
triggerParam
.
getLogId
());
XxlJobFileAppender
.
contextHolder
.
set
(
logFileName
);
XxlJobFileAppender
.
contextHolder
.
set
(
logFileName
);
ShardingUtil
.
setShardingVo
(
new
ShardingUtil
.
ShardingVO
(
triggerParam
.
getBroadcastIndex
(),
triggerParam
.
getBroadcastTotal
()));
ShardingUtil
.
setShardingVo
(
new
ShardingUtil
.
ShardingVO
(
triggerParam
.
getBroadcastIndex
(),
triggerParam
.
getBroadcastTotal
()));
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute start -----------<br>----------- Params:"
+
Arrays
.
toString
(
handlerParams
));
// execute
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute start -----------<br>----------- Params:"
+
Arrays
.
toString
(
handlerParams
));
executeResult
=
handler
.
execute
(
handlerParams
);
executeResult
=
handler
.
execute
(
handlerParams
);
if
(
executeResult
==
null
)
{
if
(
executeResult
==
null
)
{
executeResult
=
ReturnT
.
FAIL
;
executeResult
=
ReturnT
.
FAIL
;
}
}
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute end(finish) -----------<br>----------- ReturnT:"
+
executeResult
);
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
{
}
else
{
if
(
idleTimes
>
30
)
{
if
(
idleTimes
>
30
)
{
...
@@ -145,7 +131,7 @@ public class JobThread extends Thread{
...
@@ -145,7 +131,7 @@ public class JobThread extends Thread{
}
}
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
if
(
toStop
)
{
if
(
toStop
)
{
XxlJobLogger
.
log
(
"<br>----------- xxl-job
toStop, stopReason:"
+
stopReason
);
XxlJobLogger
.
log
(
"<br>----------- JobThread
toStop, stopReason:"
+
stopReason
);
}
}
StringWriter
stringWriter
=
new
StringWriter
();
StringWriter
stringWriter
=
new
StringWriter
();
...
@@ -153,7 +139,7 @@ public class JobThread extends Thread{
...
@@ -153,7 +139,7 @@ public class JobThread extends Thread{
String
errorMsg
=
stringWriter
.
toString
();
String
errorMsg
=
stringWriter
.
toString
();
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
executeResult
=
new
ReturnT
<
String
>(
ReturnT
.
FAIL_CODE
,
errorMsg
);
XxlJobLogger
.
log
(
"----------- xxl-job JobThread Exception:"
+
errorMsg
);
XxlJobLogger
.
log
(
"<br>----------- xxl-job job execute end(error) -----------<br>----------- ReturnT:"
+
executeResult
);
}
finally
{
}
finally
{
if
(
triggerParam
!=
null
)
{
if
(
triggerParam
!=
null
)
{
// callback handler info
// callback handler info
...
@@ -179,6 +165,6 @@ public class JobThread extends Thread{
...
@@ -179,6 +165,6 @@ public class JobThread extends Thread{
}
}
}
}
logger
.
info
(
">
>>>>>>>>>>> xxl-job JobThread stoped, hashCode:{}"
,
Thread
.
currentThread
());
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