fix(job-thread): add synchronized block to avoid repeat trigger job

Add synchronized block around triggerLogIdSet check and addition to ensure thread-safety
and prevent repeated job triggers. This update modifies the JobThread class to handle
concurrent access to triggerLogIdSet properly.
3.2.0-release
leqiuhong 1 year ago
parent e5d26ba277
commit c96cb6d41a

@ -60,12 +60,13 @@ public class JobThread extends Thread{
*/ */
public ReturnT<String> pushTriggerQueue(TriggerParam triggerParam) { public ReturnT<String> pushTriggerQueue(TriggerParam triggerParam) {
// avoid repeat // avoid repeat
synchronized (this){
if (triggerLogIdSet.contains(triggerParam.getLogId())) { if (triggerLogIdSet.contains(triggerParam.getLogId())) {
logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId()); logger.info(">>>>>>>>>>> repeate trigger job, logId:{}", triggerParam.getLogId());
return new ReturnT<String>(ReturnT.FAIL_CODE, "repeate trigger job, logId:" + triggerParam.getLogId()); return new ReturnT<String>(ReturnT.FAIL_CODE, "repeate trigger job, logId:" + triggerParam.getLogId());
} }
triggerLogIdSet.add(triggerParam.getLogId()); triggerLogIdSet.add(triggerParam.getLogId());
}
triggerQueue.add(triggerParam); triggerQueue.add(triggerParam);
return ReturnT.SUCCESS; return ReturnT.SUCCESS;
} }

Loading…
Cancel
Save