提交 d82c57d2 编写于 作者: W wangtao01

enhance singleFactory and set properties encoding=utf-8

上级 8ae34348
......@@ -19,19 +19,22 @@ public final class SingletonFactory {
public static <T> T getInstance(Class<T> c) {
String key = c.toString();
Object instance = null;
synchronized (c) {
instance = OBJECT_MAP.get(key);
if (instance == null) {
try {
instance = c.getDeclaredConstructor().newInstance();
OBJECT_MAP.put(key, instance);
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
if (instance == null) {
synchronized (SingletonFactory.class) {
instance = OBJECT_MAP.get(key);
if (instance == null) {
try {
instance = c.getDeclaredConstructor().newInstance();
OBJECT_MAP.put(key, instance);
} catch (IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
}
return c.cast(instance);
}
}
......@@ -4,7 +4,9 @@ import lombok.extern.slf4j.Slf4j;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
/**
......@@ -23,9 +25,11 @@ public final class PropertiesFileUtils {
rpcConfigPath = url.getPath() + fileName;
}
Properties properties = null;
try (FileInputStream fileInputStream = new FileInputStream(rpcConfigPath)) {
try (InputStreamReader inputStreamReader = new InputStreamReader(
new FileInputStream(rpcConfigPath)
, StandardCharsets.UTF_8)) {
properties = new Properties();
properties.load(fileInputStream);
properties.load(inputStreamReader);
} catch (IOException e) {
log.error("occur exception when read properties file [{}]", fileName);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册