One more tweak to avoid calling startAgent if there's already a local agent.
This commit is contained in:
@@ -62,13 +62,23 @@ public class SpringBootApp {
|
||||
private VirtualMachine vm;
|
||||
private VirtualMachineDescriptor vmd;
|
||||
|
||||
private static final String LOCAL_CONNECTOR_ADDRESS = "com.sun.management.jmxremote.localConnectorAddress";
|
||||
|
||||
private final Supplier<String> jmxConnect = Suppliers.memoize(() -> {
|
||||
String address = null;
|
||||
try {
|
||||
return vm.startLocalManagementAgent();
|
||||
address = vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
return null;
|
||||
//ignore
|
||||
}
|
||||
if (address==null) {
|
||||
try {
|
||||
address = vm.startLocalManagementAgent();
|
||||
} catch (IOException e) {
|
||||
Log.log(e);
|
||||
}
|
||||
}
|
||||
return address;
|
||||
});
|
||||
|
||||
private static SpringBootAppCache cache = new SpringBootAppCache();
|
||||
@@ -77,6 +87,11 @@ public class SpringBootApp {
|
||||
return cache.getAllRunningJavaApps();
|
||||
}
|
||||
|
||||
private String show(String msg, String value) {
|
||||
System.err.println(msg+value);
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Map that contains the boot apps, mapping the process ID -> boot app accessor object
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user