|
@@ -3,6 +3,7 @@ package com.xxl.job.core.thread;
|
|
import com.xxl.job.core.biz.model.HandleCallbackParam;
|
|
import com.xxl.job.core.biz.model.HandleCallbackParam;
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
import com.xxl.job.core.biz.model.ReturnT;
|
|
import com.xxl.job.core.biz.model.TriggerParam;
|
|
import com.xxl.job.core.biz.model.TriggerParam;
|
|
|
|
+import com.xxl.job.core.enums.ExecutorBlockStrategyEnum;
|
|
import com.xxl.job.core.handler.IJobHandler;
|
|
import com.xxl.job.core.handler.IJobHandler;
|
|
import com.xxl.job.core.log.XxlJobFileAppender;
|
|
import com.xxl.job.core.log.XxlJobFileAppender;
|
|
import com.xxl.job.core.log.XxlJobLogger;
|
|
import com.xxl.job.core.log.XxlJobLogger;
|
|
@@ -31,6 +32,9 @@ public class JobThread extends Thread{
|
|
private boolean toStop = false;
|
|
private boolean toStop = false;
|
|
private String stopReason;
|
|
private String stopReason;
|
|
|
|
|
|
|
|
+ private boolean running = false;
|
|
|
|
+
|
|
|
|
+
|
|
public JobThread(IJobHandler handler) {
|
|
public JobThread(IJobHandler handler) {
|
|
this.handler = handler;
|
|
this.handler = handler;
|
|
triggerQueue = new LinkedBlockingQueue<TriggerParam>();
|
|
triggerQueue = new LinkedBlockingQueue<TriggerParam>();
|
|
@@ -40,14 +44,33 @@ public class JobThread extends Thread{
|
|
return handler;
|
|
return handler;
|
|
}
|
|
}
|
|
|
|
|
|
- public void pushTriggerQueue(TriggerParam triggerParam) {
|
|
|
|
|
|
+ public ReturnT<String> pushTriggerQueue(TriggerParam triggerParam, ExecutorBlockStrategyEnum blockStrategy) {
|
|
|
|
+ // avoid repeat
|
|
if (triggerLogIdSet.contains(triggerParam.getLogId())) {
|
|
if (triggerLogIdSet.contains(triggerParam.getLogId())) {
|
|
logger.debug("repeate trigger job, logId:{}", triggerParam.getLogId());
|
|
logger.debug("repeate trigger job, logId:{}", triggerParam.getLogId());
|
|
- return;
|
|
|
|
|
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "repeate trigger job, logId:" + triggerParam.getLogId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // block strategy
|
|
|
|
+ if (ExecutorBlockStrategyEnum.DISCARD_LATER == blockStrategy) {
|
|
|
|
+ // discard when running
|
|
|
|
+ if (running) {
|
|
|
|
+ return new ReturnT<String>(ReturnT.FAIL_CODE, "任务阻塞:"+ExecutorBlockStrategyEnum.DISCARD_LATER.getTitle());
|
|
|
|
+ }
|
|
|
|
+ } else if (ExecutorBlockStrategyEnum.COVER_EARLY == blockStrategy) {
|
|
|
|
+ // kill running old and clear queue
|
|
|
|
+ if (running) {
|
|
|
|
+ this.interrupt();
|
|
|
|
+ }
|
|
|
|
+ triggerQueue.clear();
|
|
|
|
+ triggerLogIdSet.clear();
|
|
|
|
+ } else {
|
|
|
|
+ // just add to queue
|
|
}
|
|
}
|
|
|
|
|
|
triggerLogIdSet.add(triggerParam.getLogId());
|
|
triggerLogIdSet.add(triggerParam.getLogId());
|
|
triggerQueue.add(triggerParam);
|
|
triggerQueue.add(triggerParam);
|
|
|
|
+ return ReturnT.SUCCESS;
|
|
}
|
|
}
|
|
|
|
|
|
public void toStop(String stopReason) {
|
|
public void toStop(String stopReason) {
|
|
@@ -59,15 +82,17 @@ public class JobThread extends Thread{
|
|
this.toStop = true;
|
|
this.toStop = true;
|
|
this.stopReason = stopReason;
|
|
this.stopReason = stopReason;
|
|
}
|
|
}
|
|
-
|
|
|
|
- int i = 1;
|
|
|
|
|
|
+
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
while(!toStop){
|
|
while(!toStop){
|
|
|
|
+ running = false;
|
|
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 triggerParam = triggerQueue.poll(3L, TimeUnit.SECONDS);
|
|
TriggerParam triggerParam = triggerQueue.poll(3L, TimeUnit.SECONDS);
|
|
if (triggerParam!=null) {
|
|
if (triggerParam!=null) {
|
|
|
|
+ running = true;
|
|
triggerLogIdSet.remove(triggerParam.getLogId());
|
|
triggerLogIdSet.remove(triggerParam.getLogId());
|
|
|
|
|
|
// parse param
|
|
// parse param
|