
net.abc.tool.util.config.PeriodPropertyUtils Maven / Gradle / Ivy
package net.abc.tool.util.config;
import java.io.IOException;
import java.io.InputStream;
/**
* @author: zhangwei
* @date: 15:46/2018-12-06
*
* 存在 bug
*/
class PeriodPropertyUtils extends BasePropertyUtils {
private static final Class SUPPORT = PeriodPropertyUtils.class;
private static volatile String resource;
private static boolean conver = true;
private static int interval = 10000;
public PeriodPropertyUtils() throws IOException {
this(DEFALUE_CONFIG_NAME);
}
public PeriodPropertyUtils(String resource) throws IOException {
this(resource, true);
}
public PeriodPropertyUtils(String resource, boolean conver) throws IOException {
this.conver = conver;
this.resource = resource;
loadConfig();
Thread period = new Thread(() ->{
while (true){
try {
loadConfig();
Thread.sleep(interval);
}catch (Exception e){
e.printStackTrace();
try {
Thread.sleep(interval);
} catch (InterruptedException e1) {
// ignore
}
}
}
});
period.setName("period-property-util-daemon");
period.setDaemon(true);
period.start();
}
private void loadConfig() throws IOException {
if(resource != null) {
InputStream input = loadResource(resource);
updateParamMap(SUPPORT, input, conver);
}
}
public static String get(String key){
return get(SUPPORT, key);
}
public static String get(String key, String defalue){
return get(SUPPORT, key, defalue);
}
public static Long getLong(String key){
return getLong(SUPPORT, key);
}
public static Long getLong(String key, Long defalue){
return getLong(SUPPORT, key, defalue);
}
public static Integer getInt(String key){
return getInt(SUPPORT, key);
}
public static Integer getInt(String key, Integer defalue){
return getInt(SUPPORT, key, defalue);
}
public static Short getShort(String key){
return getShort(SUPPORT, key);
}
public static Short getShort(String key, Short defalue){
return getShort(SUPPORT, key, defalue);
}
public static Double getDouble(String key){
return getDouble(SUPPORT, key);
}
public static Double getDouble(String key, Double defalue){
return getDouble(SUPPORT, key, defalue);
}
public static Float getFloat(String key){
return getFloat(SUPPORT, key);
}
public static Float getFloat(String key, Float defalue){
return getFloat(SUPPORT, key, defalue);
}
public static Boolean getBoolean(String key){
return getBoolean(SUPPORT, key);
}
public static Boolean getBoolean(String key, Boolean defalue){
return getBoolean(SUPPORT, key, defalue);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy