diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/sch/manage/AutoCreateTask.java b/lms/nladmin-system/src/main/java/org/nl/wms/sch/manage/AutoCreateTask.java index 489df89..60ed206 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/sch/manage/AutoCreateTask.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/sch/manage/AutoCreateTask.java @@ -12,6 +12,8 @@ import org.nl.modules.wql.core.bean.WQLObject; import org.nl.modules.wql.util.SpringContextHolder; import org.nl.wms.sch.AcsUtil; import org.nl.wms.sch.task.AcsTaskDTO; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; import org.reflections.Reflections; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -19,12 +21,12 @@ import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.concurrent.TimeUnit; @Slf4j @Component("autoCreateTask") public class AutoCreateTask { // 下发acs的任务集合 - private List taskList = null; private Set> subTypes = null; WQLObject taskTab = null; @@ -36,13 +38,27 @@ public class AutoCreateTask { subTypes = reflections.getSubTypesOf(AbstractAcsTask.class); } if (ObjectUtil.isNull(taskTab)) taskTab = WQLObject.getWQLObject("sch_base_task"); - taskList = new ArrayList<>(); - this.doExecute(); + RLock lock = SpringContextHolder.getBean(RedissonClient.class).getFairLock("autoCreateTask"); + boolean try_lock = false; + try { + try_lock = lock.tryLock(0, TimeUnit.SECONDS); + if (try_lock) { + this.doExecute(); + } + } catch (Exception e) { + log.error("auto create task error !", e); + } finally { + if (try_lock) { + lock.unlock(); + } + } } private void doExecute() { + ArrayList taskList = new ArrayList<>(); + subTypes.forEach(clz -> { // 调用AbstractAcsTask类的每个子类的schedule()方法 try {