Commit 485ba5830cf19fc53b3f3e65d7c71137ae7caf1f

Authored by 潘钊
1 parent 228a199d

线程统一启动

src/main/java/com/bsth/XDApplication.java
@@ -4,8 +4,11 @@ import com.bsth.data.BasicData; @@ -4,8 +4,11 @@ import com.bsth.data.BasicData;
4 import com.bsth.data.ThreadMonotor; 4 import com.bsth.data.ThreadMonotor;
5 import com.bsth.data.car_out_info.UpdateDBThread; 5 import com.bsth.data.car_out_info.UpdateDBThread;
6 import com.bsth.data.directive.DirectivesPstThread; 6 import com.bsth.data.directive.DirectivesPstThread;
  7 +import com.bsth.data.forecast.SampleTimeDataLoader;
7 import com.bsth.data.gpsdata.thread.GpsDataLoaderThread; 8 import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
8 import com.bsth.data.gpsdata.thread.OfflineMonitorThread; 9 import com.bsth.data.gpsdata.thread.OfflineMonitorThread;
  10 +import com.bsth.data.msg_queue.DirectivePushQueue;
  11 +import com.bsth.data.msg_queue.WebSocketPushQueue;
9 import com.bsth.data.schedule.edit_logs.SeiPstThread; 12 import com.bsth.data.schedule.edit_logs.SeiPstThread;
10 import com.bsth.data.schedule.late_adjust.ScheduleLateThread; 13 import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
11 import com.bsth.data.schedule.thread.CalcOilThread; 14 import com.bsth.data.schedule.thread.CalcOilThread;
@@ -56,6 +59,8 @@ public class XDApplication implements CommandLineRunner { @@ -56,6 +59,8 @@ public class XDApplication implements CommandLineRunner {
56 ThreadMonotor threadMonotor; 59 ThreadMonotor threadMonotor;
57 @Autowired 60 @Autowired
58 SeiPstThread seiPstThread; 61 SeiPstThread seiPstThread;
  62 + @Autowired
  63 + SampleTimeDataLoader sampleTimeDataLoader;
59 64
60 private static long timeDiff; 65 private static long timeDiff;
61 private static long timeDiffTraffic; 66 private static long timeDiffTraffic;
@@ -102,7 +107,7 @@ public class XDApplication implements CommandLineRunner { @@ -102,7 +107,7 @@ public class XDApplication implements CommandLineRunner {
102 //dayOfSchedule.dataRecovery(); 107 //dayOfSchedule.dataRecovery();
103 //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS); 108 //sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
104 //实际排班更新线程 109 //实际排班更新线程
105 - //sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS); 110 + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
106 //实际排班延迟入库线程 111 //实际排班延迟入库线程
107 //sexec.scheduleWithFixedDelay(schedulePstThread, 60, 15, TimeUnit.SECONDS); 112 //sexec.scheduleWithFixedDelay(schedulePstThread, 60, 15, TimeUnit.SECONDS);
108 //班次修正日志延迟入库 113 //班次修正日志延迟入库
@@ -116,30 +121,32 @@ public class XDApplication implements CommandLineRunner { @@ -116,30 +121,32 @@ public class XDApplication implements CommandLineRunner {
116 public void prodInit(){ 121 public void prodInit(){
117 log.info("prodInit..."); 122 log.info("prodInit...");
118 ScheduledExecutorService sexec = Application.mainServices; 123 ScheduledExecutorService sexec = Application.mainServices;
119 - //发车信息  
120 - sexec.scheduleWithFixedDelay(fcxxUpdateThread, 60, 40, TimeUnit.SECONDS);  
121 - //抓取GPS数据  
122 - sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);  
123 - //GPS设备掉离线  
124 - sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);  
125 - //班次更新线程  
126 - sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);  
127 - //班次延迟入库线程  
128 - sexec.scheduleWithFixedDelay(schedulePstThread, 60, 10, TimeUnit.SECONDS);  
129 - //班次修正日志入库  
130 - sexec.scheduleWithFixedDelay(seiPstThread, 60, 60, TimeUnit.SECONDS);  
131 - //检查班次误点  
132 - sexec.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS);  
133 - //调度指令延迟入库  
134 - sexec.scheduleWithFixedDelay(directivesPstThread, 180, 100, TimeUnit.SECONDS); 124 +
  125 + /** 线调业务 */
  126 + sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);//抓取GPS数据
  127 + sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);//GPS设备掉离线
  128 + sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);//班次更新线程
  129 + sexec.scheduleWithFixedDelay(schedulePstThread, 60, 10, TimeUnit.SECONDS);//班次延迟入库线程
  130 + sexec.scheduleWithFixedDelay(seiPstThread, 60, 60, TimeUnit.SECONDS);//班次修正日志入库
  131 + sexec.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS);//检查班次误点
  132 + sexec.scheduleWithFixedDelay(directivesPstThread, 180, 100, TimeUnit.SECONDS);//调度指令延迟入库
  133 + sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
  134 + sexec.scheduleWithFixedDelay(sampleTimeDataLoader, 12, 120 * 60, TimeUnit.SECONDS);//到离站预测需要的站点间耗时数据
  135 + sexec.scheduleWithFixedDelay(basicDataLoader, 2, 2, TimeUnit.HOURS);//基础数据更新
  136 + DirectivePushQueue.start();//消息队列 -指令,系统下发的
  137 + WebSocketPushQueue.start();//消息队列 -webSocket ,推送至线调web页面的
  138 +
  139 + /** 线调为其他程序提供的数据 --写入数据库 */
  140 + sexec.scheduleWithFixedDelay(fcxxUpdateThread, 60, 40, TimeUnit.SECONDS);//发车信息(发车屏、信息发布)
  141 + //线路首末班数据(网关用,班次更新时写入)
  142 + //com.bsth.data.schedule.f_a_l.FirstAndLastHandler
  143 + //无法自动完成的班次信息(网关用,补信号)
  144 +
135 145
136 //运管处静态数据提交 146 //运管处静态数据提交
137 log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处"); 147 log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处");
138 sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiffTraffic / 1000, 60 * 60 * 24, TimeUnit.SECONDS); 148 sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiffTraffic / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
139 //计算油、公里加注 149 //计算油、公里加注
140 sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS); 150 sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
141 -  
142 - //线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)  
143 - sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);  
144 } 151 }
145 } 152 }
src/main/java/com/bsth/data/BasicData.java
1 package com.bsth.data; 1 package com.bsth.data;
2 2
3 -import com.bsth.Application;  
4 import com.bsth.data.gpsdata.arrival.GeoCacheData; 3 import com.bsth.data.gpsdata.arrival.GeoCacheData;
5 import com.bsth.data.pinyin.PersionPinYinBuffer; 4 import com.bsth.data.pinyin.PersionPinYinBuffer;
6 import com.bsth.entity.*; 5 import com.bsth.entity.*;
@@ -13,12 +12,10 @@ import org.apache.commons.lang3.StringUtils; @@ -13,12 +12,10 @@ import org.apache.commons.lang3.StringUtils;
13 import org.slf4j.Logger; 12 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
16 -import org.springframework.boot.CommandLineRunner;  
17 import org.springframework.jdbc.core.JdbcTemplate; 15 import org.springframework.jdbc.core.JdbcTemplate;
18 import org.springframework.stereotype.Component; 16 import org.springframework.stereotype.Component;
19 17
20 import java.util.*; 18 import java.util.*;
21 -import java.util.concurrent.TimeUnit;  
22 19
23 /** 20 /**
24 * @author PanZhao 21 * @author PanZhao
@@ -27,7 +24,7 @@ import java.util.concurrent.TimeUnit; @@ -27,7 +24,7 @@ import java.util.concurrent.TimeUnit;
27 * @date 2016年8月10日 下午3:27:45 24 * @date 2016年8月10日 下午3:27:45
28 */ 25 */
29 @Component 26 @Component
30 -public class BasicData implements CommandLineRunner { 27 +public class BasicData {
31 28
32 //公司代码和公司名对照(K: 公司编码,V:公司名) 29 //公司代码和公司名对照(K: 公司编码,V:公司名)
33 public static Map<String, String> businessCodeNameMap; 30 public static Map<String, String> businessCodeNameMap;
@@ -80,14 +77,6 @@ public class BasicData implements CommandLineRunner { @@ -80,14 +77,6 @@ public class BasicData implements CommandLineRunner {
80 77
81 static Logger logger = LoggerFactory.getLogger(BasicData.class); 78 static Logger logger = LoggerFactory.getLogger(BasicData.class);
82 79
83 - @Autowired  
84 - BasicDataLoader dataLoader;  
85 -  
86 - @Override  
87 - public void run(String... arg0) throws Exception {  
88 - Application.mainServices.scheduleWithFixedDelay(dataLoader, 2, 2, TimeUnit.HOURS);  
89 - }  
90 -  
91 public static String getStationNameByCode(String code, String prefix){ 80 public static String getStationNameByCode(String code, String prefix){
92 String name = stationCode2NameMap.get(code); 81 String name = stationCode2NameMap.get(code);
93 return name != null? name: stationCode2NameMap.get(prefix + code); 82 return name != null? name: stationCode2NameMap.get(prefix + code);
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
1 package com.bsth.data.forecast; 1 package com.bsth.data.forecast;
2 2
3 -import com.bsth.Application;  
4 import com.bsth.data.forecast.entity.ForecastResult; 3 import com.bsth.data.forecast.entity.ForecastResult;
5 import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem; 4 import com.bsth.data.forecast.entity.ForecastResult.ForecastResultItem;
6 import com.bsth.data.forecast.entity.SimpleRoute; 5 import com.bsth.data.forecast.entity.SimpleRoute;
@@ -13,7 +12,6 @@ import com.google.common.collect.ArrayListMultimap; @@ -13,7 +12,6 @@ import com.google.common.collect.ArrayListMultimap;
13 import org.slf4j.Logger; 12 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
16 -import org.springframework.boot.CommandLineRunner;  
17 import org.springframework.stereotype.Component; 15 import org.springframework.stereotype.Component;
18 16
19 import java.text.DecimalFormat; 17 import java.text.DecimalFormat;
@@ -21,7 +19,6 @@ import java.util.ArrayList; @@ -21,7 +19,6 @@ import java.util.ArrayList;
21 import java.util.HashMap; 19 import java.util.HashMap;
22 import java.util.List; 20 import java.util.List;
23 import java.util.Map; 21 import java.util.Map;
24 -import java.util.concurrent.TimeUnit;  
25 22
26 /** 23 /**
27 * 24 *
@@ -32,10 +29,7 @@ import java.util.concurrent.TimeUnit; @@ -32,10 +29,7 @@ import java.util.concurrent.TimeUnit;
32 * 29 *
33 */ 30 */
34 @Component 31 @Component
35 -public class ForecastRealServer implements CommandLineRunner {  
36 -  
37 - @Autowired  
38 - SampleTimeDataLoader dataLoader; 32 +public class ForecastRealServer {
39 33
40 @Autowired 34 @Autowired
41 DayOfSchedule dayOfSchedule; 35 DayOfSchedule dayOfSchedule;
@@ -57,12 +51,6 @@ public class ForecastRealServer implements CommandLineRunner { @@ -57,12 +51,6 @@ public class ForecastRealServer implements CommandLineRunner {
57 forecastMap = new HashMap<>(); 51 forecastMap = new HashMap<>();
58 } 52 }
59 53
60 - @Override  
61 - public void run(String... arg0) throws Exception {  
62 - //2小时更新一次站点间耗时数据  
63 - Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS);  
64 - }  
65 -  
66 /** 54 /**
67 * 55 *
68 * @Title: forecast 56 * @Title: forecast
src/main/java/com/bsth/data/msg_queue/DirectivePushQueue.java
@@ -5,7 +5,6 @@ import com.bsth.service.directive.DirectiveService; @@ -5,7 +5,6 @@ import com.bsth.service.directive.DirectiveService;
5 import org.slf4j.Logger; 5 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 6 import org.slf4j.LoggerFactory;
7 import org.springframework.beans.BeansException; 7 import org.springframework.beans.BeansException;
8 -import org.springframework.boot.CommandLineRunner;  
9 import org.springframework.context.ApplicationContext; 8 import org.springframework.context.ApplicationContext;
10 import org.springframework.context.ApplicationContextAware; 9 import org.springframework.context.ApplicationContextAware;
11 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
@@ -17,7 +16,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; @@ -17,7 +16,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
17 * Created by panzhao on 2017/5/11. 16 * Created by panzhao on 2017/5/11.
18 */ 17 */
19 @Component 18 @Component
20 -public class DirectivePushQueue implements CommandLineRunner, ApplicationContextAware { 19 +public class DirectivePushQueue implements ApplicationContextAware {
21 20
22 static ConcurrentLinkedQueue<QueueData_Directive> linkedList; 21 static ConcurrentLinkedQueue<QueueData_Directive> linkedList;
23 static DataPushThread thread; 22 static DataPushThread thread;
@@ -80,10 +79,10 @@ public class DirectivePushQueue implements CommandLineRunner, ApplicationContext @@ -80,10 +79,10 @@ public class DirectivePushQueue implements CommandLineRunner, ApplicationContext
80 return linkedList.size(); 79 return linkedList.size();
81 } 80 }
82 81
83 - @Override 82 +/* @Override
84 public void run(String... strings) throws Exception { 83 public void run(String... strings) throws Exception {
85 start(); 84 start();
86 - } 85 + }*/
87 86
88 @Override 87 @Override
89 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 88 public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
src/main/java/com/bsth/data/msg_queue/WebSocketPushQueue.java
@@ -3,7 +3,6 @@ package com.bsth.data.msg_queue; @@ -3,7 +3,6 @@ package com.bsth.data.msg_queue;
3 import com.bsth.common.Constants; 3 import com.bsth.common.Constants;
4 import org.slf4j.Logger; 4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
6 -import org.springframework.boot.CommandLineRunner;  
7 import org.springframework.stereotype.Component; 6 import org.springframework.stereotype.Component;
8 import org.springframework.web.socket.TextMessage; 7 import org.springframework.web.socket.TextMessage;
9 import org.springframework.web.socket.WebSocketSession; 8 import org.springframework.web.socket.WebSocketSession;
@@ -15,7 +14,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; @@ -15,7 +14,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
15 * Created by panzhao on 2017/5/11. 14 * Created by panzhao on 2017/5/11.
16 */ 15 */
17 @Component 16 @Component
18 -public class WebSocketPushQueue implements CommandLineRunner { 17 +public class WebSocketPushQueue {
19 18
20 static ConcurrentLinkedQueue<QueueData> linkedList; 19 static ConcurrentLinkedQueue<QueueData> linkedList;
21 static DataPushThread thread; 20 static DataPushThread thread;
@@ -54,10 +53,6 @@ public class WebSocketPushQueue implements CommandLineRunner { @@ -54,10 +53,6 @@ public class WebSocketPushQueue implements CommandLineRunner {
54 return linkedList.size(); 53 return linkedList.size();
55 } 54 }
56 55
57 - @Override  
58 - public void run(String... strings) throws Exception {  
59 - start();  
60 - }  
61 56
62 public static class DataPushThread extends Thread { 57 public static class DataPushThread extends Thread {
63 58