in daemon/src/main/java/org/mvndaemon/mvnd/daemon/DaemonMemoryStatus.java [103:142]
public DaemonMemoryStatus(ScheduledExecutorService executor) {
List<GarbageCollectorMXBean> garbageCollectors = ManagementFactory.getGarbageCollectorMXBeans();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
GcStrategy strategy = null;
GarbageCollectorMXBean garbageCollector = null;
MemoryPoolMXBean heapMemoryPoolMXBean = null;
MemoryPoolMXBean nonHeapMemoryPoolMXBean = null;
for (GcStrategy testStrategy : GcStrategy.values()) {
garbageCollector = garbageCollectors.stream()
.filter(gc -> gc.getName().equals(testStrategy.garbageCollector))
.findFirst()
.orElse(null);
heapMemoryPoolMXBean = memoryPoolMXBeans.stream()
.filter(mp -> mp.getName().equals(testStrategy.heapMemoryPool))
.findFirst()
.orElse(null);
nonHeapMemoryPoolMXBean = memoryPoolMXBeans.stream()
.filter(mp -> mp.getName().equals(testStrategy.nonHeapMemoryPool))
.findFirst()
.orElse(null);
if (garbageCollector != null && heapMemoryPoolMXBean != null && nonHeapMemoryPoolMXBean != null) {
strategy = testStrategy;
break;
}
}
if (strategy != null) {
this.strategy = strategy;
this.garbageCollectorMXBean = garbageCollector;
this.heapMemoryPoolMXBean = heapMemoryPoolMXBean;
this.nonHeapMemoryPoolMXBean = nonHeapMemoryPoolMXBean;
this.clock = Clock.systemUTC();
executor.scheduleAtFixedRate(this::gatherData, 1, 1, TimeUnit.SECONDS);
} else {
this.strategy = null;
this.garbageCollectorMXBean = null;
this.heapMemoryPoolMXBean = null;
this.nonHeapMemoryPoolMXBean = null;
this.clock = null;
}
}