public class PropertiesUtil {
private static Properties prop = null;
static {
prop = new Properties();
loadData();
Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(new Runnable() {
public void run() {
loadData();
}
}, 5, 5, TimeUnit.SECONDS);
}
private static void loadData() {
InputStream in = null;
try {
in = Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties");
prop.load(in);
} catch (IOException e) {
System.out.println("读取application.properties出错");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
System.out.println("Fail to close inputStream" + e);
}
}
}
}
public static String getPropertyByKey(String key) {
String value = prop.getProperty(key);
return (value== null || value =="") ? "" : value;
}
Java使用线程读取配置文件内容
最新推荐文章于 2023-02-27 02:42:26 发布