fix(performance): CommonUtil initConfig 改为异步非阻塞读取

This commit is contained in:
yukaidi
2026-05-29 00:33:27 +08:00
parent 0dfee8ab22
commit 6dfa770137

View File

@@ -100,18 +100,21 @@ public class CommonUtil {
} }
/** /**
* 处理其他配置 * 处理其他配置(异步非阻塞方式)
* *
* @param configName configName * @param configName configName
*/ */
public static void initConfig(String configName, Class<?> tClass) { public static void initConfig(String configName, Class<?> tClass) {
URL resource = tClass.getResource("/conf/" + configName); URL resource = tClass.getResource("/conf/" + configName);
if (resource == null) throw new RuntimeException("路径不存在"); if (resource == null) throw new RuntimeException("路径不存在");
Buffer buffer = VertxHolder.getVertxInstance().fileSystem().readFileBlocking(resource.getPath()); VertxHolder.getVertxInstance().fileSystem().readFile(resource.getPath())
.onSuccess(buffer -> {
JsonObject entries = new JsonObject(buffer); JsonObject entries = new JsonObject(buffer);
Map<String, Object> map = entries.getMap(); Map<String, Object> map = entries.getMap();
LocalConstant.put(configName, map); LocalConstant.put(configName, map);
LOGGER.info("读取配置{}成功", configName); LOGGER.info("读取配置{}成功", configName);
})
.onFailure(err -> LOGGER.error("读取配置{}失败", configName, err));
} }
public static <T> Set<T> sortClassSet(Set<Class<? extends T>> set) { public static <T> Set<T> sortClassSet(Set<Class<? extends T>> set) {