StartCommand.java
1.21 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
package com.bsth;
import com.bsth.thread.PersonnelUpdateThread;
import com.bsth.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
/**
* 随应用启动运行
*
*/
@Component
public class StartCommand implements CommandLineRunner{
public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(2);
Logger log = LoggerFactory.getLogger(this.getClass());
private static long timeDiff;
@Autowired
PersonnelUpdateThread personnelUpdateThread;
static {
// 中午12:00
timeDiff = (DateUtils.getTimestamp() + 1000 * 60 * 60 * 24) - System.currentTimeMillis();
}
@Override
public void run(String... arg0){
try {
log.info("在:"+timeDiff / 1000 / 60 + "分钟后开始同步数据");
personnelUpdateThread.run();
//mainServices.scheduleAtFixedRate(personnelUpdateThread, timeDiff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);//timeDiff / 1000
} catch (Exception e) {
e.printStackTrace();
}
}
}