我有一个主线程和子线程,其中,在ScheduledThreadPool Executor中,每个固定时间,主线程用于子生成的线程池和主线程轮询数据库。 我的任务是防止主线程在每个下一个延迟时间轮询数据库。 如何做到这一点,以防止主服务器每隔5分钟(固定的延迟时间)轮询数据库
它应该像这样工作: 仅轮询DB一次即可获得活动进程列表。 对于每个计划的固定延迟,子线程应在执行时无需再次轮询数据库
@Scheduled(fixedDelayString = 30000)
public void processServices() {
try {
logger.debug("Entering processServices in MasterProcessThread ");
// Getting process details and schedule
List<ProcessDomain> activeProcessList = processDomainDao.getActiveProcessDomainSchedule();
logger.info("getDomainData for flag is Active :: " + activeProcessList.size());
// Iterating over active processList to create child threads
for (ProcessDomain activeProcessDomain : activeProcessList) {
Timestamp nextRunTS = activeProcessDomain.getProcessSchedule().getProcessNextRunScheduleTime();
Long nextRunTime = (nextRunTS != null ? nextRunTS.getTime() : null);
Long startTS = activeProcessDomain.getProcessSchedule().getProcessScheduleTime().getTime();
Long currentTS = System.currentTimeMillis();
boolean isPreviousRunSucc = (activeProcessDomain.getProcessRunHistory().getPreviousSuccFlag() != null
&& activeProcessDomain.getProcessRunHistory().getPreviousSuccFlag().equals("Y")) ? true : false;
Future future = null;
// Initializing the child threads and start processing
if (((nextRunTime == null && currentTS >= startTS) || (nextRunTime != null && currentTS >= nextRunTime))
&& isPreviousRunSucc) {
Callable task = beanServiceThreadFactory.getBeanThread(activeProcessDomain.getProcessName(),
activeProcessDomain);
future = stp.submit(task);
if (future.isDone()){
stp.shutdown();
}
}
}
} catch (Exception e) {