|
|
|
@ -16,8 +16,7 @@ import java.io.PrintWriter;
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* handler thread
|
|
|
|
@ -106,6 +105,7 @@ public class JobThread extends Thread{
|
|
|
|
|
|
|
|
|
|
TriggerParam triggerParam = null;
|
|
|
|
|
ReturnT<String> executeResult = null;
|
|
|
|
|
ExecutorService singleThread = Executors.newSingleThreadExecutor();
|
|
|
|
|
try {
|
|
|
|
|
// to check toStop signal, we need cycle, so wo cannot use queue.take(), instand of poll(timeout)
|
|
|
|
|
triggerParam = triggerQueue.poll(3L, TimeUnit.SECONDS);
|
|
|
|
@ -121,7 +121,27 @@ public class JobThread extends Thread{
|
|
|
|
|
|
|
|
|
|
// execute
|
|
|
|
|
XxlJobLogger.log("<br>----------- xxl-job job execute start -----------<br>----------- Param:" + triggerParam.getExecutorParams());
|
|
|
|
|
executeResult = handler.execute(triggerParam.getExecutorParams());
|
|
|
|
|
int executeTimeout = triggerParam.getExecuteTimeout();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final TriggerParam finalTriggerParam = triggerParam;
|
|
|
|
|
|
|
|
|
|
Future<ReturnT<String>> future = singleThread.submit(new Callable<ReturnT<String>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public ReturnT<String> call() throws Exception {
|
|
|
|
|
return handler.execute(finalTriggerParam.getExecutorParams());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (executeTimeout > 0) {
|
|
|
|
|
executeResult = future.get(executeTimeout, TimeUnit.SECONDS);
|
|
|
|
|
} else {
|
|
|
|
|
executeResult = future.get();
|
|
|
|
|
}
|
|
|
|
|
} catch (TimeoutException timeoutException) {
|
|
|
|
|
executeResult = ReturnT.TIMEOUT;
|
|
|
|
|
}
|
|
|
|
|
if (executeResult == null) {
|
|
|
|
|
executeResult = IJobHandler.FAIL;
|
|
|
|
|
}
|
|
|
|
@ -144,6 +164,9 @@ public class JobThread extends Thread{
|
|
|
|
|
|
|
|
|
|
XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------");
|
|
|
|
|
} finally {
|
|
|
|
|
if (singleThread != null) {
|
|
|
|
|
singleThread.shutdown();
|
|
|
|
|
}
|
|
|
|
|
if(triggerParam != null) {
|
|
|
|
|
// callback handler info
|
|
|
|
|
if (!toStop) {
|
|
|
|
|