Pārlūkot izejas kodu

合并PR-3506,修复小概率情况下任务重复调度问题;

xuxueli 2 mēneši atpakaļ
vecāks
revīzija
90fae1be9d

+ 1 - 0
doc/XXL-JOB官方文档.md

@@ -2551,6 +2551,7 @@ public void execute() {
 - 5、【优化】异常页面处理逻辑优化,新增兜底落地页配置;
 - 6、【重构】ReturnT 重构,简化代码结构,提升API易用性以及可维护性;
 - 7、【修复】合并PR-3738,修复拼写问题;
+- 8、【修复】合并PR-3506,修复小概率情况下任务重复调度问题;
 
 - 3、【规划中】登录安全升级,密码加密处理算法从Md5改为Sha256;
 ```

+ 5 - 4
xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java

@@ -43,7 +43,8 @@ public class JobThread extends Thread{
 		this.jobId = jobId;
 		this.handler = handler;
 		this.triggerQueue = new LinkedBlockingQueue<TriggerParam>();
-		this.triggerLogIdSet = Collections.synchronizedSet(new HashSet<Long>());
+		//this.triggerLogIdSet = Collections.synchronizedSet(new HashSet<Long>());
+		this.triggerLogIdSet = ConcurrentHashMap.newKeySet();
 
 		// assign job thread name
 		this.setName("xxl-job, JobThread-"+jobId+"-"+System.currentTimeMillis());
@@ -59,13 +60,13 @@ public class JobThread extends Thread{
      * @return
      */
 	public ReturnT<String> pushTriggerQueue(TriggerParam triggerParam) {
-		// avoid repeat
-		if (triggerLogIdSet.contains(triggerParam.getLogId())) {
+        // avoid repeat
+		if (!triggerLogIdSet.add(triggerParam.getLogId())) {
 			logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId());
 			return new ReturnT<String>(ReturnT.FAIL_CODE, "repeate trigger job, logId:" + triggerParam.getLogId());
 		}
 
-		triggerLogIdSet.add(triggerParam.getLogId());
+		// push trigger queue
 		triggerQueue.add(triggerParam);
         return ReturnT.ofSuccess();
 	}