任务线程轮空30次后自动销毁,降低低频任务的无效线程消耗。

v1.8.2
xuxueli 7 years ago
parent 7a5f3acf31
commit 3138d48afa

@ -864,6 +864,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 3、XxlJobLogger的日志多参数支持 - 3、XxlJobLogger的日志多参数支持
- 4、路由策略新增 "忙碌转移" 模式:按照顺序依次进行空闲检测,第一个空闲检测成功的机器选定为目标执行器并发起调度; - 4、路由策略新增 "忙碌转移" 模式:按照顺序依次进行空闲检测,第一个空闲检测成功的机器选定为目标执行器并发起调度;
- 5、路由策略代码重构 - 5、路由策略代码重构
- 6、执行器重复注册问题修复
- 7、任务线程轮空30次后自动销毁降低低频任务的无效线程消耗。
#### TODO LIST #### TODO LIST
- 1、任务权限管理执行器为粒度分配权限核心操作校验权限 - 1、任务权限管理执行器为粒度分配权限核心操作校验权限
@ -874,8 +876,6 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 6、任务依赖流程图子任务+会签任务,各节点日志; - 6、任务依赖流程图子任务+会签任务,各节点日志;
- 7、调度任务优先级 - 7、调度任务优先级
- 8、移除quartz依赖重写调度模块新增或恢复任务时将下次执行记录插入delayqueue调度中心集群竞争分布式锁成功节点批量加载到期delayqueue数据批量执行。 - 8、移除quartz依赖重写调度模块新增或恢复任务时将下次执行记录插入delayqueue调度中心集群竞争分布式锁成功节点批量加载到期delayqueue数据批量执行。
- 9、任务线程轮空30次后自动销毁降低低频任务的无效线程消耗。
- 10、注册界面出现重复地址问题
## 七、其他 ## 七、其他

@ -46,7 +46,9 @@ public class JobRegistryMonitorHelper {
if (registryList == null) { if (registryList == null) {
registryList = new ArrayList<String>(); registryList = new ArrayList<String>();
} }
registryList.add(item.getRegistryValue()); if (!registryList.contains(item.getRegistryValue())) {
registryList.add(item.getRegistryValue());
}
temp.put(groupKey, registryList); temp.put(groupKey, registryList);
} }
} }

@ -125,7 +125,7 @@ public class XxlJobExecutor implements ApplicationContextAware, ApplicationListe
// ---------------------------------- job thread repository // ---------------------------------- job thread repository
private static ConcurrentHashMap<Integer, JobThread> JobThreadRepository = new ConcurrentHashMap<Integer, JobThread>(); private static ConcurrentHashMap<Integer, JobThread> JobThreadRepository = new ConcurrentHashMap<Integer, JobThread>();
public static JobThread registJobThread(int jobId, IJobHandler handler, String removeOldReason){ public static JobThread registJobThread(int jobId, IJobHandler handler, String removeOldReason){
JobThread newJobThread = new JobThread(handler); JobThread newJobThread = new JobThread(jobId, handler);
newJobThread.start(); newJobThread.start();
logger.info(">>>>>>>>>>> xxl-job regist JobThread success, jobId:{}, handler:{}", new Object[]{jobId, handler}); logger.info(">>>>>>>>>>> xxl-job regist JobThread success, jobId:{}, handler:{}", new Object[]{jobId, handler});

@ -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.executor.XxlJobExecutor;
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;
@ -23,7 +24,8 @@ import java.util.concurrent.TimeUnit;
*/ */
public class JobThread extends Thread{ public class JobThread extends Thread{
private static Logger logger = LoggerFactory.getLogger(JobThread.class); private static Logger logger = LoggerFactory.getLogger(JobThread.class);
private int jobId;
private IJobHandler handler; private IJobHandler handler;
private LinkedBlockingQueue<TriggerParam> triggerQueue; private LinkedBlockingQueue<TriggerParam> triggerQueue;
private ConcurrentHashSet<Integer> triggerLogIdSet; // avoid repeat trigger for the same TRIGGER_LOG_ID private ConcurrentHashSet<Integer> triggerLogIdSet; // avoid repeat trigger for the same TRIGGER_LOG_ID
@ -32,12 +34,14 @@ public class JobThread extends Thread{
private String stopReason; private String stopReason;
private boolean running = false; // if running job private boolean running = false; // if running job
private int idleTimes = 0; // idel times
public JobThread(IJobHandler handler) { public JobThread(int jobId, IJobHandler handler) {
this.jobId = jobId;
this.handler = handler; this.handler = handler;
triggerQueue = new LinkedBlockingQueue<TriggerParam>(); this.triggerQueue = new LinkedBlockingQueue<TriggerParam>();
triggerLogIdSet = new ConcurrentHashSet<Integer>(); this.triggerLogIdSet = new ConcurrentHashSet<Integer>();
} }
public IJobHandler getHandler() { public IJobHandler getHandler() {
return handler; return handler;
@ -88,11 +92,13 @@ public class JobThread extends Thread{
public void run() { public void run() {
while(!toStop){ while(!toStop){
running = false; running = false;
idleTimes++;
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; running = true;
idleTimes = 0;
triggerLogIdSet.remove(triggerParam.getLogId()); triggerLogIdSet.remove(triggerParam.getLogId());
// parse param // parse param
@ -126,9 +132,6 @@ public class JobThread extends Thread{
XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------"); XxlJobLogger.log("<br>----------- JobThread Exception:" + errorMsg + "<br>----------- xxl-job job execute end(error) -----------");
} }
// callback handler info // callback handler info
if (!toStop) { if (!toStop) {
@ -139,8 +142,12 @@ public class JobThread extends Thread{
ReturnT<String> stopResult = new ReturnT<String>(ReturnT.FAIL_CODE, stopReason + " [业务运行中,被强制终止]"); ReturnT<String> stopResult = new ReturnT<String>(ReturnT.FAIL_CODE, stopReason + " [业务运行中,被强制终止]");
TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), stopResult)); TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), stopResult));
} }
} else {
if (idleTimes > 3) {
XxlJobExecutor.removeJobThread(jobId, "excutor idel times over limit.");
}
} }
} catch (Exception e) { } catch (Throwable e) {
if (toStop) { if (toStop) {
XxlJobLogger.log("<br>----------- xxl-job toStop, stopReason:" + stopReason); XxlJobLogger.log("<br>----------- xxl-job toStop, stopReason:" + stopReason);
} }

Loading…
Cancel
Save