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 4 import com.bsth.data.gpsdata_v2.cache.GpsCacheData;
5 5 import com.bsth.data.gpsdata_v2.entity.GpsEntity;
6 6 import com.bsth.data.gpsdata_v2.handlers.*;
7   -import com.bsth.email.SendEmailController;
8   -import com.bsth.email.entity.EmailBean;
9 7 import com.google.common.collect.ArrayListMultimap;
10 8 import org.apache.commons.lang3.StringUtils;
11 9 import org.slf4j.Logger;
... ... @@ -17,8 +15,6 @@ import java.util.*;
17 15 import java.util.concurrent.CountDownLatch;
18 16 import java.util.concurrent.ExecutorService;
19 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 37 ReverseRouteProcess reverseRouteProcess;
42 38 @Autowired
43 39 GpsRealData gpsRealData;
44   - // 发送邮件
45   - @Autowired
46   - private SendEmailController sendEmailController;
47 40  
48 41  
49 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 47 public static CountDownLatch count;
66 48  
67 49 static long lastTime;
... ... @@ -69,22 +51,7 @@ public class DataHandleProcess {
69 51 public static boolean isBlock() {
70 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 55 public void handle(List<GpsEntity> list) {
89 56 try {
90 57 if (list.size() == 0)
... ... @@ -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 90 //加入实时gps对照
149 91 for (GpsEntity gps : list)
... ... @@ -173,7 +115,6 @@ public class DataHandleProcess {
173 115 Collections.sort(list, comp);
174 116 GpsEntity gps;
175 117 for(int i = 0,len = list.size(); i< len ;i ++){
176   - if (Thread.currentThread().isInterrupted()) break;
177 118 gps = list.get(i);
178 119  
179 120 try {
... ...