Skip to content

Commit 4cb9d95

Browse files
committed
Use ProcessHandler to get the process ID
Closes gh-28178
1 parent 8addb38 commit 4cb9d95

File tree

1 file changed

+2
-4
lines changed
  • spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system

1 file changed

+2
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import java.io.FileNotFoundException;
2121
import java.io.FileWriter;
2222
import java.io.IOException;
23-
import java.lang.management.ManagementFactory;
2423
import java.nio.file.Files;
2524
import java.nio.file.attribute.PosixFilePermission;
2625
import java.util.Set;
@@ -51,8 +50,7 @@ protected ApplicationPid(String pid) {
5150

5251
private String getPid() {
5352
try {
54-
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
55-
return jvmName.split("@")[0];
53+
return Long.toString(ProcessHandle.current().pid());
5654
}
5755
catch (Throwable ex) {
5856
return null;

0 commit comments

Comments
 (0)