//缓存单线程
private static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
// 定时刷新内存数据
executorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
// 刷新内存参数
flushData();
// 根据reloadCache参数开关判断是否执行下次刷新任务,0:关闭,不刷新内存;1:开启,定时刷新内存,进程shutdown后不能恢复
Environment environment = ApplicationContextHelper.applicationContext.getEnvironment();
String reloadCache = PropertyUtil.getProperties(environment.getProperty("conf.file.path"), "reloadCache");
if ("0".equals(reloadCache)) {
executorService.shutdown();
}
}
}, 1L, 600L, TimeUnit.SECONDS); // 项目启动后1秒开始执行,此后10分钟刷新一次
}