Commit f19a4a3977406d688bc74f4b2ae8ca4a8ad6f4cf

Authored by 游瑞烽
2 parents 163a5e69 3c708086

update

src/main/java/com/bsth/XDApplication.java
@@ -72,7 +72,7 @@ public class XDApplication implements CommandLineRunner { @@ -72,7 +72,7 @@ public class XDApplication implements CommandLineRunner {
72 @Autowired 72 @Autowired
73 GpsDataLoaderThread gpsDataLoader; 73 GpsDataLoaderThread gpsDataLoader;
74 @Autowired 74 @Autowired
75 - RfidDataLoaderThread rfidDataLoader; 75 + RfidDataLoaderThread rfidDataLoaderThread;
76 76
77 @Autowired 77 @Autowired
78 OfflineMonitorThread offlineMonitorThread; 78 OfflineMonitorThread offlineMonitorThread;
@@ -165,7 +165,7 @@ public class XDApplication implements CommandLineRunner { @@ -165,7 +165,7 @@ public class XDApplication implements CommandLineRunner {
165 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程 165 sexec.scheduleWithFixedDelay(scheduleRefreshThread, 10, 120, TimeUnit.SECONDS);//班次更新线程
166 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点 166 sexec.scheduleWithFixedDelay(scheduleLateThread, 140, 20, TimeUnit.SECONDS);//检查班次误点
167 sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据 167 sexec.scheduleWithFixedDelay(gpsDataLoader, 100, 2, TimeUnit.SECONDS);//抓取GPS数据
168 - sexec.scheduleWithFixedDelay(rfidDataLoader, 5, 5, TimeUnit.SECONDS);//抓取RFID数据 168 + sexec.scheduleWithFixedDelay(rfidDataLoaderThread, 10, 20, TimeUnit.SECONDS);//抓取GPS数据
169 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码 169 sexec.scheduleWithFixedDelay(fixedCheckStationCodeThread, 60, 60 * 5, TimeUnit.SECONDS);//检查班次站点编码
170 170
171 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线 171 sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
@@ -6,7 +6,6 @@ import com.bsth.data.gpsdata_v2.entity.GpsEntity; @@ -6,7 +6,6 @@ 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; 7 import com.bsth.email.SendEmailController;
8 import com.bsth.email.entity.EmailBean; 8 import com.bsth.email.entity.EmailBean;
9 -import com.fasterxml.jackson.databind.ObjectMapper;  
10 import com.google.common.collect.ArrayListMultimap; 9 import com.google.common.collect.ArrayListMultimap;
11 import org.apache.commons.lang3.StringUtils; 10 import org.apache.commons.lang3.StringUtils;
12 import org.slf4j.Logger; 11 import org.slf4j.Logger;
@@ -63,13 +62,29 @@ public class DataHandleProcess { @@ -63,13 +62,29 @@ public class DataHandleProcess {
63 } 62 }
64 63
65 }); 64 });
  65 + public static CountDownLatch count;
66 66
67 static long lastTime; 67 static long lastTime;
68 68
69 public static boolean isBlock() { 69 public static boolean isBlock() {
70 return System.currentTimeMillis() - lastTime > 1000 * 30; 70 return System.currentTimeMillis() - lastTime > 1000 * 30;
71 } 71 }
72 - 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 +
73 public void handle(List<GpsEntity> list) { 88 public void handle(List<GpsEntity> list) {
74 try { 89 try {
75 if (list.size() == 0) 90 if (list.size() == 0)
@@ -94,24 +109,36 @@ public class DataHandleProcess { @@ -94,24 +109,36 @@ public class DataHandleProcess {
94 } 109 }
95 Set<Integer> ks = dataListMap.keySet(); 110 Set<Integer> ks = dataListMap.keySet();
96 logger.info("analyse gps size: " + list.size() + ", ks: " + ks.size()); 111 logger.info("analyse gps size: " + list.size() + ", ks: " + ks.size());
97 - CountDownLatch count = new CountDownLatch(ks.size()); 112 + count = new CountDownLatch(ks.size());
98 113
99 - logger.info(JSON.toJSONString(ks)); 114 + //logger.info(JSON.toJSONString(ks));
100 for (Integer index : ks) { 115 for (Integer index : ks) {
101 threadPool.execute(new SignalHandleThread(dataListMap.get(index), count)); 116 threadPool.execute(new SignalHandleThread(dataListMap.get(index), count));
102 } 117 }
103 118
104 119
105 //等待子线程结束 120 //等待子线程结束
106 - boolean isNormal = count.await(5000, TimeUnit.MILLISECONDS); 121 + boolean isNormal = count.await(5, TimeUnit.SECONDS);
107 if (!isNormal) { 122 if (!isNormal) {
108 try { 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 + });
109 //发送邮件 137 //发送邮件
110 EmailBean mail = new EmailBean(); 138 EmailBean mail = new EmailBean();
111 mail.setSubject("线调GPS处理"); 139 mail.setSubject("线调GPS处理");
112 - mail.setContent("GPS处理超时,检查日志信息<br/>"); 140 + mail.setContent("GPS处理超时,检查线程栈文件信息<br/>");
113 sendEmailController.sendMail("113252620@qq.com", mail); 141 sendEmailController.sendMail("113252620@qq.com", mail);
114 - logger.info(new ObjectMapper().writeValueAsString(list));  
115 logger.info("DataHandlerProcess:邮件发送成功!"); 142 logger.info("DataHandlerProcess:邮件发送成功!");
116 } catch (Exception e){ 143 } catch (Exception e){
117 logger.error("DataHandlerProcess:邮件发送失败!",e); 144 logger.error("DataHandlerProcess:邮件发送失败!",e);
@@ -142,7 +169,6 @@ public class DataHandleProcess { @@ -142,7 +169,6 @@ public class DataHandleProcess {
142 169
143 @Override 170 @Override
144 public void run() { 171 public void run() {
145 - long start = System.currentTimeMillis();  
146 try { 172 try {
147 Collections.sort(list, comp); 173 Collections.sort(list, comp);
148 GpsEntity gps; 174 GpsEntity gps;
@@ -167,18 +193,12 @@ public class DataHandleProcess { @@ -167,18 +193,12 @@ public class DataHandleProcess {
167 193
168 GpsCacheData.putGps(gps);//历史gps缓存 194 GpsCacheData.putGps(gps);//历史gps缓存
169 } catch (Throwable e) { 195 } catch (Throwable e) {
170 - logger.error("SignalHandleThread.run1", e); 196 + logger.error("", e);
171 } 197 }
172 } 198 }
173 - } catch (Exception e) {  
174 - logger.error("SignalHandleThread.run2", e);  
175 } finally { 199 } finally {
176 if (count != null) 200 if (count != null)
177 count.countDown(); 201 count.countDown();
178 -  
179 - StringBuilder sb = new StringBuilder();  
180 - sb.append("list size:").append(list.size()).append(" cost:").append(System.currentTimeMillis() - start);  
181 - logger.info(sb.toString());  
182 } 202 }
183 } 203 }
184 } 204 }
src/main/resources/application-prod.properties
1 -server.port=9088  
2 -#management.port= 9001  
3 -#management.address= 127.0.0.1  
4 -management.security.enabled=false  
5 -management.context-path=/manage  
6 -dubbo.use=true  
7 -  
8 -spring.jpa.hibernate.ddl-auto= update  
9 -spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy  
10 -#DATABASE  
11 -spring.jpa.database= MYSQL  
12 -spring.jpa.show-sql= false  
13 -spring.datasource.driver-class-name= com.mysql.jdbc.Driver  
14 -spring.datasource.url= jdbc:mysql://10.10.200.148:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false  
15 -spring.datasource.username= root  
16 -spring.datasource.password= root  
17 -  
18 -#DATASOURCE  
19 -spring.datasource.max-active=100  
20 -spring.datasource.max-idle=8  
21 -spring.datasource.min-idle=8  
22 -spring.datasource.initial-size=5  
23 -  
24 -spring.datasource.test-on-borrow=true  
25 -spring.datasource.test-on-connect=true  
26 -spring.datasource.test-on-return=true  
27 -spring.datasource.test-while-idle=true  
28 -spring.datasource.validation-query=select 1  
29 -  
30 -## gps client data  
31 -http.gps.real.cache.url= http://10.10.150.24:12580/realGps/all  
32 -## gateway real data  
33 -http.gps.real.url= http://10.10.200.79:8080/transport_server/rtgps/  
34 -## gateway send directive  
35 -#http.send.directive = http://10.10.200.79:8080/transport_server/message/  
36 -## wxsb  
37 -#http.report.url.05= http://192.168.168.154:8088/ygjwsystem_j2ee/clbx/clbx_dd.do  
38 -#http.report.url.22= http://192.168.168.154:8088/jgjwsystem_j2ee/clbx/clbx_dd.do  
39 -#http.report.url.26= http://192.168.168.154:8088/nhjwsystem_j2ee/clbx/clbx_dd.do  
40 -#http.report.url.55= http://192.168.168.154:8088/snjwsystem_j2ee/clbx/clbx_dd.do  
41 -http.report.url.05= http://116.228.197.222:8081/ygjwsystem_j2ee/clbx/clbx_dd1.do  
42 -http.report.url.22= http://116.247.73.122:9098/jgjwsystem_j2ee/clbx/clbx_dd1.do  
43 -http.report.url.26= http://116.236.141.34:8088/nhjwsystem_j2ee/clbx/clbx_dd1.do 1 +server.port=9088
  2 +#management.port= 9001
  3 +#management.address= 127.0.0.1
  4 +management.security.enabled=false
  5 +management.context-path=/manage
  6 +dubbo.use=true
  7 +
  8 +spring.jpa.hibernate.ddl-auto= update
  9 +spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
  10 +#DATABASE
  11 +spring.jpa.database= MYSQL
  12 +spring.jpa.show-sql= false
  13 +spring.datasource.driver-class-name= com.mysql.jdbc.Driver
  14 +spring.datasource.url= jdbc:mysql://10.10.200.148:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
  15 +spring.datasource.username= root
  16 +spring.datasource.password= root
  17 +#DATASOURCE
  18 +spring.datasource.max-active=100
  19 +spring.datasource.max-idle=8
  20 +spring.datasource.min-idle=8
  21 +spring.datasource.initial-size=5
  22 +
  23 +spring.datasource.test-on-borrow=true
  24 +spring.datasource.test-on-connect=true
  25 +spring.datasource.test-on-return=true
  26 +spring.datasource.test-while-idle=true
  27 +spring.datasource.validation-query=select 1
  28 +
  29 +## gps client data
  30 +http.gps.real.cache.url= http://10.10.150.24:12580/realGps/all
  31 +## gateway real data
  32 +http.gps.real.url= http://10.10.200.79:8080/transport_server/rtgps/
  33 +## gateway send directive
  34 +#http.send.directive = http://10.10.200.79:8080/transport_server/message/
  35 +## wxsb
  36 +#http.report.url.05= http://192.168.168.154:8088/ygjwsystem_j2ee/clbx/clbx_dd.do
  37 +#http.report.url.22= http://192.168.168.154:8088/jgjwsystem_j2ee/clbx/clbx_dd.do
  38 +#http.report.url.26= http://192.168.168.154:8088/nhjwsystem_j2ee/clbx/clbx_dd.do
  39 +#http.report.url.55= http://192.168.168.154:8088/snjwsystem_j2ee/clbx/clbx_dd.do
  40 +http.report.url.05= http://116.228.197.222:8081/ygjwsystem_j2ee/clbx/clbx_dd1.do
  41 +http.report.url.22= http://116.247.73.122:9098/jgjwsystem_j2ee/clbx/clbx_dd1.do
  42 +http.report.url.26= http://116.236.141.34:8088/nhjwsystem_j2ee/clbx/clbx_dd1.do
44 http.report.url.55= http://180.168.216.248:8088/snjwsystem_j2ee/clbx/clbx_dd1.do 43 http.report.url.55= http://180.168.216.248:8088/snjwsystem_j2ee/clbx/clbx_dd1.do
45 \ No newline at end of file 44 \ No newline at end of file