StartCommand.java
1.6 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
package com.bsth;
import com.bsth.server_rs.gps.buffer.GpsRefreshThread;
import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread;
import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread;
import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread;
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;
/**
* 随应用启动运行
* @author PanZhao
*
*/
@Component
public class StartCommand implements CommandLineRunner{
@Autowired
RfidCardInfoPersistenceThread rfidCardInfoPersistenceThread;
@Autowired
SchInOutDataRefreshThread schInOutDataRefreshThread;
@Autowired
ExecSchDataRefreshThread execSchDataRefreshThread;
@Autowired
GpsRefreshThread gpsRefreshThread;
@Override
public void run(String... arg0){
try {
ScheduledExecutorService sexec = Application.mainServices;
//定时将人车卡数据入库
sexec.scheduleWithFixedDelay(rfidCardInfoPersistenceThread, 120, 60 * 10, TimeUnit.SECONDS);
//定时从调度系统刷新进出场数据
sexec.scheduleWithFixedDelay(schInOutDataRefreshThread, 40, 20, TimeUnit.SECONDS);
//定时从调度系统刷新车辆正在的执行班次
sexec.scheduleWithFixedDelay(execSchDataRefreshThread, 20, 60 * 2, TimeUnit.SECONDS);
//定时刷新实时gps缓存
Application.mainServices.scheduleWithFixedDelay(gpsRefreshThread, 10, 7, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
}