From e66b83965943e8471d5e2fb616899e0c8271e840 Mon Sep 17 00:00:00 2001 From: ydpd Date: Wed, 2 Mar 2022 00:02:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/event/SipSubscribe.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java index a00ac630..4644fb0a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java @@ -23,7 +23,8 @@ public class SipSubscribe { private Map okSubscribes = new ConcurrentHashMap<>(); - private Map timeSubscribes = new ConcurrentHashMap<>(); + private Map okTimeSubscribes = new ConcurrentHashMap<>(); + private Map errorTimeSubscribes = new ConcurrentHashMap<>(); // @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 // @Scheduled(fixedRate= 100 * 60 * 60 ) @@ -33,14 +34,24 @@ public class SipSubscribe { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1); - for (String key : timeSubscribes.keySet()) { - if (timeSubscribes.get(key).before(calendar.getTime())){ + for (String key : okTimeSubscribes.keySet()) { + if (okTimeSubscribes.get(key).before(calendar.getTime())){ logger.info("[定时任务] 清理过期的订阅信息: {}", key); - errorSubscribes.remove(key); okSubscribes.remove(key); - timeSubscribes.remove(key); + okTimeSubscribes.remove(key); } } + for (String key : errorTimeSubscribes.keySet()) { + if (errorTimeSubscribes.get(key).before(calendar.getTime())){ + logger.info("[定时任务] 清理过期的订阅信息: {}", key); + errorSubscribes.remove(key); + errorTimeSubscribes.remove(key); + } + } + logger.info("okTimeSubscribes.size:{}",okTimeSubscribes.size()); + logger.info("okSubscribes.size:{}",okSubscribes.size()); + logger.info("errorTimeSubscribes.size:{}",errorTimeSubscribes.size()); + logger.info("errorSubscribes.size:{}",errorSubscribes.size()); } public interface Event { From 86f87c4665e0c3c9c2723c32c0615f85ca4b0a7c Mon Sep 17 00:00:00 2001 From: ydpd Date: Wed, 2 Mar 2022 00:24:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=86=85=E5=AD=98?= =?UTF-8?q?=E6=B3=84=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/event/SipSubscribe.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java index 4644fb0a..49c52d5e 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java @@ -26,24 +26,25 @@ public class SipSubscribe { private Map okTimeSubscribes = new ConcurrentHashMap<>(); private Map errorTimeSubscribes = new ConcurrentHashMap<>(); -// @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 + // @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 // @Scheduled(fixedRate= 100 * 60 * 60 ) - @Scheduled(cron="0 0 * * * ?") //每小时执行一次, 每个整点 + @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次 public void execute(){ logger.info("[定时任务] 清理过期的订阅信息"); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); - calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1); + calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 5); + for (String key : okTimeSubscribes.keySet()) { if (okTimeSubscribes.get(key).before(calendar.getTime())){ - logger.info("[定时任务] 清理过期的订阅信息: {}", key); +// logger.info("[定时任务] 清理过期的订阅信息: {}", key); okSubscribes.remove(key); okTimeSubscribes.remove(key); } } for (String key : errorTimeSubscribes.keySet()) { if (errorTimeSubscribes.get(key).before(calendar.getTime())){ - logger.info("[定时任务] 清理过期的订阅信息: {}", key); +// logger.info("[定时任务] 清理过期的订阅信息: {}", key); errorSubscribes.remove(key); errorTimeSubscribes.remove(key); } @@ -116,12 +117,12 @@ public class SipSubscribe { public void addErrorSubscribe(String key, SipSubscribe.Event event) { errorSubscribes.put(key, event); - timeSubscribes.put(key, new Date()); + errorTimeSubscribes.put(key, new Date()); } public void addOkSubscribe(String key, SipSubscribe.Event event) { okSubscribes.put(key, event); - timeSubscribes.put(key, new Date()); + okTimeSubscribes.put(key, new Date()); } public SipSubscribe.Event getErrorSubscribe(String key) { @@ -130,7 +131,7 @@ public class SipSubscribe { public void removeErrorSubscribe(String key) { errorSubscribes.remove(key); - timeSubscribes.remove(key); + errorTimeSubscribes.remove(key); } public SipSubscribe.Event getOkSubscribe(String key) { @@ -139,7 +140,7 @@ public class SipSubscribe { public void removeOkSubscribe(String key) { okSubscribes.remove(key); - timeSubscribes.remove(key); + okTimeSubscribes.remove(key); } public int getErrorSubscribesSize(){ return errorSubscribes.size();