mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-08-02 21:50:43 +08:00
Improve startup speed
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user