Skip to content

Commit

Permalink
Revert "perf: 刷新上下文避免重复创建调度任务"
Browse files Browse the repository at this point in the history
  • Loading branch information
KamToHung committed Jan 20, 2024
1 parent 193efd4 commit b18bb50
Showing 1 changed file with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import static org.dromara.dynamictp.common.constant.DynamicTpConst.SCHEDULE_NOTIFY_ITEMS;
Expand All @@ -52,26 +51,13 @@ public class DtpMonitor extends OnceApplicationContextEventListener {

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,
protected void onContextRefreshedEvent(ContextRefreshedEvent event) {
MONITOR_EXECUTOR.scheduleWithFixedDelay(this::run,
0, dtpProperties.getMonitorInterval(), TimeUnit.SECONDS);
}

Expand Down

0 comments on commit b18bb50

Please sign in to comment.