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

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

Loading…
Cancel
Save