Commit 0993bedb46648539bef735289f905afa3b4ef8dd

Authored by panll
Committed by Gitee
2 parents bbb808d8 86f87c46

!11 修改内存泄露

Merge pull request !11 from ydpd/wvp-28181-2.0
src/main/java/com/genersoft/iot/vmp/gb28181/event/SipSubscribe.java
@@ -23,24 +23,36 @@ public class SipSubscribe { @@ -23,24 +23,36 @@ public class SipSubscribe {
23 23
24 private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>(); 24 private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>();
25 25
26 - private Map<String, Date> timeSubscribes = new ConcurrentHashMap<>(); 26 + private Map<String, Date> okTimeSubscribes = new ConcurrentHashMap<>();
  27 + private Map<String, Date> errorTimeSubscribes = new ConcurrentHashMap<>();
27 28
28 -// @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次 29 + // @Scheduled(cron="*/5 * * * * ?") //每五秒执行一次
29 // @Scheduled(fixedRate= 100 * 60 * 60 ) 30 // @Scheduled(fixedRate= 100 * 60 * 60 )
30 - @Scheduled(cron="0 0 * * * ?") //每小时执行一次, 每个整点 31 + @Scheduled(cron="0 0/5 * * * ?") //每5分钟执行一次
31 public void execute(){ 32 public void execute(){
32 logger.info("[定时任务] 清理过期的订阅信息"); 33 logger.info("[定时任务] 清理过期的订阅信息");
33 Calendar calendar = Calendar.getInstance(); 34 Calendar calendar = Calendar.getInstance();
34 calendar.setTime(new Date()); 35 calendar.setTime(new Date());
35 - calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) - 1);  
36 - for (String key : timeSubscribes.keySet()) {  
37 - if (timeSubscribes.get(key).before(calendar.getTime())){  
38 - logger.info("[定时任务] 清理过期的订阅信息: {}", key);  
39 - errorSubscribes.remove(key); 36 + calendar.set(Calendar.MINUTE, calendar.get(Calendar.MINUTE) - 5);
  37 +
  38 + for (String key : okTimeSubscribes.keySet()) {
  39 + if (okTimeSubscribes.get(key).before(calendar.getTime())){
  40 +// logger.info("[定时任务] 清理过期的订阅信息: {}", key);
40 okSubscribes.remove(key); 41 okSubscribes.remove(key);
41 - timeSubscribes.remove(key); 42 + okTimeSubscribes.remove(key);
  43 + }
  44 + }
  45 + for (String key : errorTimeSubscribes.keySet()) {
  46 + if (errorTimeSubscribes.get(key).before(calendar.getTime())){
  47 +// logger.info("[定时任务] 清理过期的订阅信息: {}", key);
  48 + errorSubscribes.remove(key);
  49 + errorTimeSubscribes.remove(key);
42 } 50 }
43 } 51 }
  52 + logger.info("okTimeSubscribes.size:{}",okTimeSubscribes.size());
  53 + logger.info("okSubscribes.size:{}",okSubscribes.size());
  54 + logger.info("errorTimeSubscribes.size:{}",errorTimeSubscribes.size());
  55 + logger.info("errorSubscribes.size:{}",errorSubscribes.size());
44 } 56 }
45 57
46 public interface Event { 58 public interface Event {
@@ -105,12 +117,12 @@ public class SipSubscribe { @@ -105,12 +117,12 @@ public class SipSubscribe {
105 117
106 public void addErrorSubscribe(String key, SipSubscribe.Event event) { 118 public void addErrorSubscribe(String key, SipSubscribe.Event event) {
107 errorSubscribes.put(key, event); 119 errorSubscribes.put(key, event);
108 - timeSubscribes.put(key, new Date()); 120 + errorTimeSubscribes.put(key, new Date());
109 } 121 }
110 122
111 public void addOkSubscribe(String key, SipSubscribe.Event event) { 123 public void addOkSubscribe(String key, SipSubscribe.Event event) {
112 okSubscribes.put(key, event); 124 okSubscribes.put(key, event);
113 - timeSubscribes.put(key, new Date()); 125 + okTimeSubscribes.put(key, new Date());
114 } 126 }
115 127
116 public SipSubscribe.Event getErrorSubscribe(String key) { 128 public SipSubscribe.Event getErrorSubscribe(String key) {
@@ -119,7 +131,7 @@ public class SipSubscribe { @@ -119,7 +131,7 @@ public class SipSubscribe {
119 131
120 public void removeErrorSubscribe(String key) { 132 public void removeErrorSubscribe(String key) {
121 errorSubscribes.remove(key); 133 errorSubscribes.remove(key);
122 - timeSubscribes.remove(key); 134 + errorTimeSubscribes.remove(key);
123 } 135 }
124 136
125 public SipSubscribe.Event getOkSubscribe(String key) { 137 public SipSubscribe.Event getOkSubscribe(String key) {
@@ -128,7 +140,7 @@ public class SipSubscribe { @@ -128,7 +140,7 @@ public class SipSubscribe {
128 140
129 public void removeOkSubscribe(String key) { 141 public void removeOkSubscribe(String key) {
130 okSubscribes.remove(key); 142 okSubscribes.remove(key);
131 - timeSubscribes.remove(key); 143 + okTimeSubscribes.remove(key);
132 } 144 }
133 public int getErrorSubscribesSize(){ 145 public int getErrorSubscribesSize(){
134 return errorSubscribes.size(); 146 return errorSubscribes.size();