Use ProcessHandler to get the process ID

Closes gh-28178
This commit is contained in:
Andy Wilkinson
2022-05-13 14:35:41 +01:00
parent 8addb3834e
commit 4cb9d95b49

View File

@@ -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;
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 {
private String getPid() {
try {
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
return jvmName.split("@")[0];
return Long.toString(ProcessHandle.current().pid());
}
catch (Throwable ex) {
return null;