Improve startup speed

This commit is contained in:
SwallowGG
2023-12-12 23:04:39 +08:00
parent fe1b362af3
commit 3df13fc9bc
6 changed files with 74 additions and 47 deletions

View File

@ -61,6 +61,14 @@ public class ConfigUtils {
version = StringUtils.trim(FileUtil.readUtf8String(versionFile));
return version;
}
public static String getLatestLocalVersion() {
if (versionFile == null) {
log.warn("VERSION_FILE is null");
return null;
}
return StringUtils.trim(FileUtil.readUtf8String(versionFile));
}
public static ConfigJson getConfig() {
if (config == null) {
@ -91,31 +99,42 @@ public class ConfigUtils {
public static void pid() {
try {
log.error("pidinit");
ProcessHandle currentProcess = ProcessHandle.current();
long pid = currentProcess.pid();
log.error("pid:{}", pid);
String environment = StringUtils.defaultString(System.getProperty("spring.profiles.active"), "dev");
File pidFile = new File(CONFIG_BASE_PATH + File.separator + "config" + File.separator + environment + "pid");
if (!pidFile.exists()) {
FileUtil.writeUtf8String(String.valueOf(pid), pidFile);
} else {
String oldPid = FileUtil.readUtf8String(pidFile);
log.error("oldPid:{}", oldPid);
if (StringUtils.isNotBlank(oldPid)) {
Optional<ProcessHandle> processHandle = ProcessHandle.of(Long.parseLong(oldPid));
log.error("processHandle:{}", JSON.toJSONString(processHandle));
processHandle.ifPresent(handle -> {
ProcessHandle.Info info = handle.info();
String[] arguments = info.arguments().orElse(null);
log.error("arguments:{}", JSON.toJSONString(arguments));
if (arguments == null) {
return;
}
for (String argument : arguments) {
if (StringUtils.equals("chat2db-server-start.jar", argument)) {
handle.destroy();
log.error("destroy old process--------");
break;
}
if (StringUtils.equals("application", argument)) {
handle.destroy();
log.error("destroy old process--------");
break;
}
}
});
}
FileUtil.writeUtf8String(String.valueOf(pid), pidFile);
}