XDApplication.java
4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.bsth;
import com.bsth.data.BasicData;
import com.bsth.data.ThreadMonotor;
import com.bsth.data.car_out_info.UpdateDBThread;
import com.bsth.data.directive.DirectivesPstThread;
import com.bsth.data.gpsdata.thread.GpsDataLoaderThread;
import com.bsth.data.gpsdata.thread.OfflineMonitorThread;
import com.bsth.data.schedule.late_adjust.ScheduleLateThread;
import com.bsth.data.schedule.thread.CalcOilThread;
import com.bsth.data.schedule.thread.SchedulePstThread;
import com.bsth.data.schedule.thread.ScheduleRefreshThread;
import com.bsth.data.schedule.thread.SubmitToTrafficManage;
import com.bsth.util.DateUtils;
import com.bsth.util.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/**
* 线调大部分服务都在这里启动
* Created by panzhao on 2017/5/14.
*/
@Component
public class XDApplication implements CommandLineRunner {
Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
BasicData.BasicDataLoader basicDataLoader;
@Autowired
UpdateDBThread fcxxUpdateThread;
@Autowired
GpsDataLoaderThread gpsDataLoader;
@Autowired
OfflineMonitorThread offlineMonitorThread;
@Autowired
ScheduleRefreshThread scheduleRefreshThread;
@Autowired
SchedulePstThread schedulePstThread;
@Autowired
ScheduleLateThread scheduleLateThread;
@Autowired
SubmitToTrafficManage submitToTrafficManage;
@Autowired
CalcOilThread calcOilThread;
@Autowired
DirectivesPstThread directivesPstThread;
@Autowired
ThreadMonotor threadMonotor;
private static long timeDiff;
static {
timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 140) - System.currentTimeMillis();
if (timeDiff < 0)
timeDiff += (1000 * 60 * 60 * 24);
}
@Override
public void run(String... strings) throws Exception {
try {
Tools tools = new Tools("application.properties");
String environment = tools.getValue("spring.profiles.active");
//预先加载基础的对照数据
basicDataLoader.loadAllData();
switch (environment){
case "dev":
devInit();
break;
case "prod":
prodInit();
break;
}
}catch (Exception e){
log.error("线调后台启动出现异常!!", e);
System.exit(1);
}
}
public void devInit(){
ScheduledExecutorService sexec = Application.mainServices;
//抓取GPS数据
gpsDataLoader.setFlag(-1);
sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
//实际排班更新线程
sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
//实际排班延迟入库线程
sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS);
//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
}
public void prodInit(){
ScheduledExecutorService sexec = Application.mainServices;
//发车信息
sexec.scheduleWithFixedDelay(fcxxUpdateThread, 60, 40, TimeUnit.SECONDS);
//抓取GPS数据
sexec.scheduleWithFixedDelay(gpsDataLoader, 30, 2, TimeUnit.SECONDS);
//检查设备掉离线
sexec.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
//实际排班更新线程
sexec.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
//实际排班延迟入库线程
sexec.scheduleWithFixedDelay(schedulePstThread, 60, 30, TimeUnit.SECONDS);
//检查班次误点
sexec.scheduleWithFixedDelay(scheduleLateThread, 60, 30, TimeUnit.SECONDS);
//调度指令延迟入库
sexec.scheduleWithFixedDelay(directivesPstThread, 180, 180, TimeUnit.SECONDS);
//运管处静态数据提交
log.info(timeDiff / 1000 / 60 + "分钟之后提交到运管处");
sexec.scheduleAtFixedRate(submitToTrafficManage, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
//计算油、公里加注
sexec.scheduleAtFixedRate(calcOilThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
//线程监听(防止重要的线程阻塞、异常结束。以及部分主备切换工作)
sexec.scheduleWithFixedDelay(threadMonotor, 240, 60, TimeUnit.SECONDS);
}
}