private static final Logger LOGGER = LogManager.getLogger(BaseSendUpdateNews.class);
public static void timerWeather() {
//启用1个线程
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
long oneDay = 24 * 60 * 60 * 1000;
//设置每天早晨8点执行
long initDelay = getTimeMillis("08:00:00") - System.currentTimeMillis();
initDelay = initDelay > 0 ? initDelay : oneDay + initDelay;
// 循环任务,按照上一次任务的发起时间计算下一次任务的开始时间
executor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
Calendar c = Calendar.getInstance();
int day = c.get(Calendar.DAY_OF_MONTH);
if (day == 1) {
// 每天执行,若为每月1号才执行
LOGGER.info("群发消息月任务执行");
nowYreaNotUpdate();
}
}
}, initDelay, oneDay, TimeUnit.MILLISECONDS);
LOGGER.debug("每月定时群发信息监听--已启动!");
}
定时循环任务每天,每月几号
最新推荐文章于 2021-06-23 09:12:52 发布