BorrowCenter.java
2.01 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
package com.bsth.vehicle;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bsth.vehicle.directive.service.DirectiveService;
/**
*
* @ClassName: BorrowCenter
* @Description: TODO(借还车中心^_^)
* @author PanZhao
* @date 2016年7月12日 下午11:49:36
*
*/
@Component
public class BorrowCenter {
ScheduledExecutorService scheduler;
@Autowired
DirectiveService directiveService;
Logger logger = LoggerFactory.getLogger(BorrowCenter.class);
/**
* 构造函数
*/
public BorrowCenter() {
scheduler = Executors.newScheduledThreadPool(15);
}
/**
*
* @Title: put
* @param @param nbbm 车辆
* @param @param lineCode 线路代码
* @param @param type 0 借出,1归还
* @param @param time 时间
* @throws
*/
public void put(String nbbm, Integer lineCode, int type, Long time, int upDown){
Long t = System.currentTimeMillis();
if(t >= time){
//立即执行
new Thread(new ChangeThread(nbbm, lineCode, type, upDown)).start();
}
else{
//定时线程
scheduler.schedule(new ChangeThread(nbbm, lineCode, type, upDown), (time - t) / 1000, TimeUnit.SECONDS);
}
}
public class ChangeThread implements Runnable{
String nbbm;
Integer lineCode;
int type;
int upDown;
public ChangeThread(String nbbm, Integer lineCode, int type, int upDown) {
this.nbbm = nbbm;
this.lineCode = lineCode;
this.type = type;
this.upDown = upDown;
}
@Override
public void run() {
logger.info("nbbm " + (type==0?"借出":"归还") + "线路代码 " + lineCode);
directiveService.lineChange(nbbm, lineCode, null);
if(upDown != -1){
//切换走向
directiveService.upDownChange(nbbm, upDown, null);
}
}
}
}