| | |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.time.Instant; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | |
| | | } |
| | | } |
| | | // scheduleWithFixedDelay 必须等待上一个任务结束才开始计时period, cycleForCatalog表示执行的间隔 |
| | | future = threadPoolTaskScheduler.scheduleAtFixedRate(task, cycleForCatalog); |
| | | |
| | | future = threadPoolTaskScheduler.scheduleAtFixedRate(task, new Date(System.currentTimeMillis() + cycleForCatalog), cycleForCatalog); |
| | | if (future != null){ |
| | | futureMap.put(key, future); |
| | | runnableMap.put(key, task); |
| | |
| | | } |
| | | boolean result = false; |
| | | if (!ObjectUtils.isEmpty(futureMap.get(key)) && !futureMap.get(key).isCancelled() && !futureMap.get(key).isDone()) { |
| | | result = futureMap.get(key).cancel(true); |
| | | result = futureMap.get(key).cancel(false); |
| | | futureMap.remove(key); |
| | | runnableMap.remove(key); |
| | | } |
| | |
| | | public void execute(){ |
| | | if (futureMap.size() > 0) { |
| | | for (String key : futureMap.keySet()) { |
| | | if (futureMap.get(key).isDone() || futureMap.get(key).isCancelled()) { |
| | | ScheduledFuture<?> future = futureMap.get(key); |
| | | if (future.isDone() || future.isCancelled()) { |
| | | futureMap.remove(key); |
| | | runnableMap.remove(key); |
| | | } |