【线网测试数据查询频率】

This commit is contained in:
weizhihong 2023-06-30 17:17:52 +08:00
parent f7879fe0d7
commit 56b7a0d14e

View File

@ -25,9 +25,7 @@ import java.util.concurrent.atomic.AtomicLong;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 线路设备信息更新
*/
/** 线路设备信息更新 */
@Slf4j
@Service
public class LineDeviceStatusService {
@ -73,17 +71,31 @@ public class LineDeviceStatusService {
public void refreshTestData() {
List<MessageData> allMockData = nccMockDataService.loadAllTrainInitData();
DeviceStatusConvertorManager.doConvertor(allMockData);
int frequency = 1500, stopTime = 30000;
AtomicLong id = new AtomicLong(0);
AtomicLong resetTimes = new AtomicLong(stopTime);
Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay(
() -> {
int count = (int) (Math.random() * 12);
List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count);
DeviceStatusConvertorManager.doConvertor(updateMockData);
boolean isEmpty = true;
if (resetTimes.get() == stopTime) { // 代表还没有停顿不相等说明已经进入空循环
int count = (int) (Math.random() * 12);
List<MessageData> updateMockData =
nccMockDataService.loadUpdateData(id, MessageId.TRAIN_RECORD.name(), count);
DeviceStatusConvertorManager.doConvertor(updateMockData);
isEmpty = updateMockData.size() == 0;
}
if (isEmpty) { // 假数据已经用完了开始重复使用中间停顿30000ms
if (resetTimes.get() <= 0) {
id.set(0);
resetTimes.set(stopTime);
} else {
resetTimes.set(resetTimes.get() - frequency);
}
}
},
1500,
1500,
frequency,
frequency,
TimeUnit.MILLISECONDS);
}
}