Commit e87339f634e843abc1e58bb2234a193460b44e52

Authored by 王通
1 parent 929bfdae

1.GpsCacheData中HashMap替换成并发Map

# Conflicts:
#	src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
@@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSON; @@ -4,8 +4,6 @@ import com.alibaba.fastjson.JSON;
4 import com.bsth.data.gpsdata_v2.cache.GpsCacheData; 4 import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
5 import com.bsth.data.gpsdata_v2.entity.GpsEntity; 5 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
6 import com.bsth.data.gpsdata_v2.handlers.*; 6 import com.bsth.data.gpsdata_v2.handlers.*;
7 -import com.bsth.email.SendEmailController;  
8 -import com.bsth.email.entity.EmailBean;  
9 import com.google.common.collect.ArrayListMultimap; 7 import com.google.common.collect.ArrayListMultimap;
10 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
11 import org.slf4j.Logger; 9 import org.slf4j.Logger;
@@ -17,8 +15,6 @@ import java.util.*; @@ -17,8 +15,6 @@ import java.util.*;
17 import java.util.concurrent.CountDownLatch; 15 import java.util.concurrent.CountDownLatch;
18 import java.util.concurrent.ExecutorService; 16 import java.util.concurrent.ExecutorService;
19 import java.util.concurrent.Executors; 17 import java.util.concurrent.Executors;
20 -import java.util.concurrent.ThreadFactory;  
21 -import java.util.concurrent.TimeUnit;  
22 18
23 /** 19 /**
24 * 实时信号数据处理 20 * 实时信号数据处理
@@ -41,27 +37,13 @@ public class DataHandleProcess { @@ -41,27 +37,13 @@ public class DataHandleProcess {
41 ReverseRouteProcess reverseRouteProcess; 37 ReverseRouteProcess reverseRouteProcess;
42 @Autowired 38 @Autowired
43 GpsRealData gpsRealData; 39 GpsRealData gpsRealData;
44 - // 发送邮件  
45 - @Autowired  
46 - private SendEmailController sendEmailController;  
47 40
48 41
49 static Logger logger = LoggerFactory.getLogger(DataHandleProcess.class); 42 static Logger logger = LoggerFactory.getLogger(DataHandleProcess.class);
50 43
51 - final static int POOL_SIZE = 20; 44 + final static int POOL_SIZE = 9;
52 45
53 - static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new ThreadFactory() {  
54 -  
55 - @Override  
56 - public Thread newThread(Runnable r) {  
57 - // TODO Auto-generated method stub  
58 - Thread t = new Thread(r);  
59 - t.setName("GPSProcessor");  
60 -  
61 - return t;  
62 - }  
63 -  
64 - }); 46 + static ExecutorService threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1);
65 public static CountDownLatch count; 47 public static CountDownLatch count;
66 48
67 static long lastTime; 49 static long lastTime;
@@ -69,22 +51,7 @@ public class DataHandleProcess { @@ -69,22 +51,7 @@ public class DataHandleProcess {
69 public static boolean isBlock() { 51 public static boolean isBlock() {
70 return System.currentTimeMillis() - lastTime > 1000 * 30; 52 return System.currentTimeMillis() - lastTime > 1000 * 30;
71 } 53 }
72 -  
73 - private void shutdownAndAwaitTermination(ExecutorService pool) {  
74 - pool.shutdown();  
75 - try {  
76 - if (!pool.awaitTermination(500, TimeUnit.MILLISECONDS)) {  
77 - pool.shutdownNow();  
78 - }  
79 - if (!pool.awaitTermination(500, TimeUnit.MILLISECONDS)) {  
80 - logger.error("线程池无法正常终止");  
81 - }  
82 - } catch (InterruptedException e) {  
83 - pool.shutdown();  
84 - Thread.currentThread().interrupt();  
85 - }  
86 - }  
87 - 54 +
88 public void handle(List<GpsEntity> list) { 55 public void handle(List<GpsEntity> list) {
89 try { 56 try {
90 if (list.size() == 0) 57 if (list.size() == 0)
@@ -118,32 +85,7 @@ public class DataHandleProcess { @@ -118,32 +85,7 @@ public class DataHandleProcess {
118 85
119 86
120 //等待子线程结束 87 //等待子线程结束
121 - boolean isNormal = count.await(5, TimeUnit.SECONDS);  
122 - if (!isNormal) {  
123 - try {  
124 - shutdownAndAwaitTermination(threadPool);  
125 - threadPool = Executors.newFixedThreadPool(POOL_SIZE + 1, new ThreadFactory() {  
126 -  
127 - @Override  
128 - public Thread newThread(Runnable r) {  
129 - // TODO Auto-generated method stub  
130 - Thread t = new Thread(r);  
131 - t.setName("GPSProcessor");  
132 -  
133 - return t;  
134 - }  
135 -  
136 - });  
137 - //发送邮件  
138 - EmailBean mail = new EmailBean();  
139 - mail.setSubject("线调GPS处理");  
140 - mail.setContent("GPS处理超时,检查线程栈文件信息<br/>");  
141 - sendEmailController.sendMail("113252620@qq.com", mail);  
142 - logger.info("DataHandlerProcess:邮件发送成功!");  
143 - } catch (Exception e){  
144 - logger.error("DataHandlerProcess:邮件发送失败!",e);  
145 - }  
146 - } 88 + count.await();
147 89
148 //加入实时gps对照 90 //加入实时gps对照
149 for (GpsEntity gps : list) 91 for (GpsEntity gps : list)
@@ -173,7 +115,6 @@ public class DataHandleProcess { @@ -173,7 +115,6 @@ public class DataHandleProcess {
173 Collections.sort(list, comp); 115 Collections.sort(list, comp);
174 GpsEntity gps; 116 GpsEntity gps;
175 for(int i = 0,len = list.size(); i< len ;i ++){ 117 for(int i = 0,len = list.size(); i< len ;i ++){
176 - if (Thread.currentThread().isInterrupted()) break;  
177 gps = list.get(i); 118 gps = list.get(i);
178 119
179 try { 120 try {