From f88c70d38ce1c9c0d04460d0c225373c84dc2eca Mon Sep 17 00:00:00 2001
From: dengming <dengming@ctfo.com>
Date: 星期四, 10 三月 2022 17:27:07 +0800
Subject: [PATCH] 删除重复字段,channelId字段查询了两次

---
 src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java |   38 +++++++++++++++++++++++++++++++++-----
 1 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
index 145c29b..80e39f5 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
@@ -3,9 +3,9 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
-import org.springframework.scheduling.support.CronTrigger;
 import org.springframework.stereotype.Component;
 
+import java.util.Date;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledFuture;
@@ -26,17 +26,45 @@
         return new ThreadPoolTaskScheduler();
     }
 
-    public String startCron(String key, Runnable task, String corn) {
-        stopCron(key);
-        ScheduledFuture future = threadPoolTaskScheduler.schedule(task, new CronTrigger(corn));
+    /**
+     * 寰幆鎵ц鐨勪换鍔�
+     * @param key 浠诲姟ID
+     * @param task 浠诲姟
+     * @param cycleForCatalog 闂撮殧
+     * @return
+     */
+    public String startCron(String key, Runnable task, int cycleForCatalog) {
+        stop(key);
+        // scheduleWithFixedDelay 蹇呴』绛夊緟涓婁竴涓换鍔$粨鏉熸墠寮�濮嬭鏃秔eriod锛� cycleForCatalog琛ㄧず鎵ц鐨勯棿闅�
+        ScheduledFuture future = threadPoolTaskScheduler.scheduleWithFixedDelay(task, cycleForCatalog * 1000L);
         futureMap.put(key, future);
         return "startCron";
     }
 
-    public void stopCron(String key) {
+    /**
+     * 寤舵椂浠诲姟
+     * @param key 浠诲姟ID
+     * @param task 浠诲姟
+     * @param delay 寤舵椂 /绉�
+     * @return
+     */
+    public String startDelay(String key, Runnable task, int delay) {
+        stop(key);
+        Date starTime = new Date(System.currentTimeMillis() + delay * 1000);
+        // scheduleWithFixedDelay 蹇呴』绛夊緟涓婁竴涓换鍔$粨鏉熸墠寮�濮嬭鏃秔eriod锛� cycleForCatalog琛ㄧず鎵ц鐨勯棿闅�
+        ScheduledFuture future = threadPoolTaskScheduler.schedule(task, starTime);
+        futureMap.put(key, future);
+        return "startCron";
+    }
+
+    public void stop(String key) {
         if (futureMap.get(key) != null && !futureMap.get(key).isCancelled()) {
             futureMap.get(key).cancel(true);
         }
     }
 
+    public boolean contains(String key) {
+        return futureMap.get(key) != null;
+    }
+
 }

--
Gitblit v1.8.0