class DtpMonitor extends OnceApplicationContextEventListener {

    private static final ScheduledExecutorService MONITOR_EXECUTOR = ThreadPoolCreator.newScheduledThreadPool("dtp-monitor", 1);

    private final DtpProperties dtpProperties;

    private ScheduledFuture<?> monitorFuture;

    private int monitorInterval;

    public DtpMonitor(DtpProperties dtpProperties) {
        this.dtpProperties = dtpProperties;
    }

    @Override
    protected synchronized void onContextRefreshedEvent(ContextRefreshedEvent event) {
        // if monitorInterval is same as before, do nothing.
        if (monitorInterval == dtpProperties.getMonitorInterval()) {
            return;
        }
        // cancel old monitor task.
        if (monitorFuture != null) {
            monitorFuture.cancel(true);
        }
        monitorInterval = dtpProperties.getMonitorInterval();
        monitorFuture = MONITOR_EXECUTOR.scheduleWithFixedDelay(this::run,
                0, dtpProperties.getMonitorInterval(), TimeUnit.SECONDS);
    }

    private void run() {
        Set<String> executorNames = DtpRegistry.getAllExecutorNames();
        checkAlarm(executorNames);
        collectMetrics(executorNames);
    }

    private void checkAlarm(Set<String> executorNames) {
        executorNames.forEach(name -> {
            ExecutorWrapper wrapper = DtpRegistry.getExecutorWrapper(name);
            AlarmManager.tryAlarmAsync(wrapper, SCHEDULE_NOTIFY_ITEMS);
        });
        publishAlarmCheckEvent();
    }

    private void collectMetrics(Set<String> executorNames) {<FILL_FUNCTION_BODY>}

    private void doCollect(ThreadPoolStats threadPoolStats) {
        try {
            CollectorHandler.getInstance().collect(threadPoolStats, dtpProperties.getCollectorTypes());
        } catch (Exception e) {
            log.error("DynamicTp monitor, metrics collect error.", e);
        }
    }

    private void publishCollectEvent() {
        CollectEvent event = new CollectEvent(this, dtpProperties);
        ApplicationContextHolder.publishEvent(event);
    }

    private void publishAlarmCheckEvent() {
        AlarmCheckEvent event = new AlarmCheckEvent(this, dtpProperties);
        ApplicationContextHolder.publishEvent(event);
    }

    public static void destroy() {
        MONITOR_EXECUTOR.shutdownNow();
    }
}

        if (!dtpProperties.isEnabledCollect()) {
            return;
        }
        executorNames.forEach(x -> {
            ExecutorWrapper wrapper = DtpRegistry.getExecutorWrapper(x);
            doCollect(ExecutorConverter.toMetrics(wrapper));
        });
        publishCollectEvent();
    
<methods>public void onApplicationEvent(ApplicationEvent) ,public final void setApplicationContext(ApplicationContext) <variables>private ApplicationContext applicationContext