class MemoryMetricsCaptor implements Runnable {

    private double max = -1;

    private double used = -1;

    public double getLongLivedMemoryUsage() {
        if (max == -1 || used == -1) {
            return -1;
        }
        return used / max;
    }

    @Override
    public void run() {<FILL_FUNCTION_BODY>}

    private double getUsageValue(MemoryPoolMXBean memoryPoolMXBean, ToLongFunction<MemoryUsage> getter) {
        MemoryUsage usage = getUsage(memoryPoolMXBean);
        if (usage == null) {
            return -1;
        }
        return getter.applyAsLong(usage);
    }

    private MemoryUsage getUsage(MemoryPoolMXBean memoryPoolMXBean) {
        try {
            return memoryPoolMXBean.getUsage();
        } catch (InternalError e) {
            return null;
        }
    }

    private boolean isLongLivedPool(String name) {
        return StringUtils.isNotBlank(name) && (name.endsWith("Old Gen") ||
                name.endsWith("Tenured Gen") ||
                "ZHeap".equals(name) ||
                "Shenandoah".equals(name) ||
                name.endsWith("balanced-old") ||
                name.contains("tenured") ||
                "JavaHeap".equals(name)
        );
    }
}

        try {
            val memoryPoolBeans = ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class);
            if (CollectionUtils.isEmpty(memoryPoolBeans)) {
                return;
            }
            for (MemoryPoolMXBean memoryPoolBean : memoryPoolBeans) {
                String name = memoryPoolBean.getName();
                boolean isLongLivedPool = isLongLivedPool(name);
                if (isLongLivedPool) {
                    used = getUsageValue(memoryPoolBean, MemoryUsage::getUsed);
                    max = getUsageValue(memoryPoolBean, MemoryUsage::getMax);
                    break;
                }
            }
        } catch (Exception e) {
            log.warn("MemoryMetricsCaptor run failed.", e);
        }
    
<no_super_class>