// 监控文件的变化,重新加载
executor.submit(new Runnable() {
@Override
public void run() {
try {
final Path path = FileSystems.getDefault().getPath(getMonitorDir());
System.out.println(path);
final WatchService watchService = FileSystems.getDefault().newWatchService();
final WatchKey watchKey = path.register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
while (true) {
final WatchKey wk = watchService.take();
for (WatchEvent<?> event : wk.pollEvents()) {
final Path changed = (Path) event.context();
Path absolute = path.resolve(changed);
File configFile = absolute.toFile();
long lastModified = configFile.lastModified();
logger.info(lastModified + "----------------");
// 利用文件时间戳,防止触发两次
if (changed.endsWith(getLicenseName()) && lastModified != LAST_MOD && configFile.length > 0) {
logger.info("----------------- reloading -----------------");
LAST_MOD = lastModified; // 保存上一次时间戳
UPDATED = true; // 设置标志位
}
}
if (UPDATED) {
reloadFile(); // 重新加载
}
// reset the key
boolean valid = wk.reset();
if (!valid) {
logger.error("watch key invalid!");
}
}
} catch (Exception e) {
logger.error("");
}
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有