@Override
    public Monitor getMonitor(URL url) {
        url = url.setPath(MonitorService.class.getName()).addParameter(INTERFACE_KEY, MonitorService.class.getName());
        String key = url.toServiceStringWithoutResolving();
        Monitor monitor = MONITORS.get(key);
        Future<Monitor> future = FUTURES.get(key);
        if (monitor != null || future != null) {
            return monitor;
        }

        LOCK.lock();
        try {
            monitor = MONITORS.get(key);
            future = FUTURES.get(key);
            if (monitor != null || future != null) {
                return monitor;
            }

            final URL monitorUrl = url;
            future = EXECUTOR.submit(() -> {
                try {
                    Monitor m = createMonitor(monitorUrl);
                    MONITORS.put(key, m);
                    FUTURES.remove(key);
                    return m;
                } catch (Throwable e) {
                    logger.warn(
                            COMMON_MONITOR_EXCEPTION,
                            "",
                            "",
                            "Create monitor failed, monitor data will not be collected until you fix this problem. monitorUrl: "
                                    + monitorUrl,
                            e);
                    return null;
                }
            });
            FUTURES.put(key, future);
            return null;
        } finally {
            // unlock
            LOCK.unlock();
        }
    }
@Test
    void testMonitorFactoryGroupCache() throws Exception {
        URL url1 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=aaa");
        URL url2 = URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=bbb");
        Monitor monitor1 = monitorFactory.getMonitor(url1);
        Monitor monitor2 = monitorFactory.getMonitor(url2);
        if (monitor1 == null || monitor2 == null) {
            Thread.sleep(2000);
            monitor1 = monitorFactory.getMonitor(url1);
            monitor2 = monitorFactory.getMonitor(url2);
        }
        Assertions.assertNotSame(monitor1, monitor2);
    }