|
@@ -10,6 +10,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.locks.Lock;
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
+
|
|
|
/**
|
|
|
* 大屏项目定时任务
|
|
|
*
|
|
@@ -29,6 +33,8 @@ public class ScreenTask {
|
|
|
@Autowired
|
|
|
private ParkSystemService parkSystemService;
|
|
|
|
|
|
+ private final Lock lock = new ReentrantLock();
|
|
|
+
|
|
|
/**
|
|
|
* 每小时执行一次数据拉取
|
|
|
*/
|
|
@@ -37,7 +43,7 @@ public class ScreenTask {
|
|
|
try {
|
|
|
log.info("定时开始执行 开始时间:{}", DateUtil.now());
|
|
|
ebaSystemService.initData();
|
|
|
- energyPlatformService.initData();
|
|
|
+ // energyPlatformService.initData();
|
|
|
ParkUtils.getLoginToken();
|
|
|
log.info("定时执行结束 结束时间:{}", DateUtil.now());
|
|
|
} catch (Exception e) {
|
|
@@ -48,13 +54,15 @@ public class ScreenTask {
|
|
|
/**
|
|
|
* 每3秒处理6条数据
|
|
|
*/
|
|
|
- @Scheduled(cron = "*/3 * * * * ?")
|
|
|
+ @Scheduled(cron = "*/5 * * * * ?")
|
|
|
public void exec() {
|
|
|
try {
|
|
|
- log.info("开始处理数据 开始时间:{}", DateUtil.now());
|
|
|
- // 获取10条进行处理
|
|
|
- boolean result = parkSystemService.taskExec(6);
|
|
|
- log.info("数据处理结束 结束时间:{} 处理结果:{}", DateUtil.now(), result);
|
|
|
+ if (lock.tryLock(2, TimeUnit.SECONDS)) {
|
|
|
+ log.info("开始处理数据 开始时间:{}", DateUtil.now());
|
|
|
+ // 获取10条进行处理
|
|
|
+ boolean result = parkSystemService.taskExec(9);
|
|
|
+ log.info("数据处理结束 结束时间:{} 处理结果:{}", DateUtil.now(), result);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
log.error("定时任务执行出现错误:", e);
|
|
|
}
|