Browse Source

Use ProcessHandler to get the process ID

Closes gh-28178
pull/31033/head
Andy Wilkinson 4 years ago
parent
commit
4cb9d95b49
  1. 6
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPid.java

6
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/ApplicationPid.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import java.io.File; @@ -20,7 +20,6 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
@ -51,8 +50,7 @@ public class ApplicationPid { @@ -51,8 +50,7 @@ public class ApplicationPid {
private String getPid() {
try {
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
return jvmName.split("@")[0];
return Long.toString(ProcessHandle.current().pid());
}
catch (Throwable ex) {
return null;

Loading…
Cancel
Save