测试,线程中断测试
parent
4e33949c95
commit
230e69f64b
|
@ -6,6 +6,7 @@ import com.muyu.utils.VehicleUtils;
|
|||
import com.muyu.vehicle.core.LocalContainer;
|
||||
import com.muyu.vehicle.model.VehicleData;
|
||||
import com.muyu.vehicle.model.properties.MqttProperties;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.math.BigDecimal;
|
||||
|
@ -21,22 +22,30 @@ import static java.lang.Thread.sleep;
|
|||
* @description:
|
||||
* @Date 2023-11-17 上午 09:02
|
||||
*/
|
||||
@Log4j2
|
||||
public class Test {
|
||||
|
||||
public static CountDownLatch countDownLatch;
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
log.info("开始生成VIN");
|
||||
long genVinStartTime = System.currentTimeMillis();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
list.add(VehicleUtils.genVin());
|
||||
}
|
||||
countDownLatch = new CountDownLatch(list.size());
|
||||
log.info("生成VIN结束:[{}MS]", System.currentTimeMillis()-genVinStartTime);
|
||||
log.info("开始创建车辆");
|
||||
long initVehicleStartTime = System.currentTimeMillis();
|
||||
list.forEach(Test::init);
|
||||
log.info("创建车辆结束:[{}MS]", System.currentTimeMillis()-initVehicleStartTime);
|
||||
list.forEach(vin -> {
|
||||
init(vin);
|
||||
new Thread(new TestThread(vin)).start();
|
||||
VehicleInstance vehicleIns = LocalContainer.getVehicleInstance(vin);
|
||||
vehicleIns.initVehicleThread();
|
||||
vehicleIns.startSend();
|
||||
});
|
||||
countDownLatch.await();
|
||||
ThreadPool.shutdown();
|
||||
// countDownLatch.await();
|
||||
// ThreadPool.shutdown();
|
||||
}
|
||||
|
||||
public static void init(String vin){
|
||||
|
|
|
@ -105,10 +105,9 @@ public class VehicleInstance {
|
|||
options.setKeepAliveInterval(60);
|
||||
// 连接
|
||||
client.connect(options);
|
||||
log.info("mqtt初始化成功");
|
||||
log.info("车辆:[{}] 客户端初始化成功", getVin());
|
||||
} catch (MqttException e) {
|
||||
log.error("mqtt链接服务器异常:{}", e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
log.error("车辆:[{}] 客户端初始化异常", getVin(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ public class VehicleData {
|
|||
//车速
|
||||
sb.append(getValue(speed,6));
|
||||
//总里程
|
||||
sb.append(getValue(mileage.toString(),11));
|
||||
sb.append(getValue(mileage == null ? "" : mileage.toString(),11));
|
||||
// 总电压
|
||||
sb.append(getValue(voltage,6));
|
||||
//总电流
|
||||
|
@ -291,7 +291,7 @@ public class VehicleData {
|
|||
//绝缘电阻 79 - 87
|
||||
sb.append(getValue(resistance,9));
|
||||
//档位
|
||||
sb.append(gear);
|
||||
sb.append(gear == null ? "D" : gear);
|
||||
// 加速踏板行程值
|
||||
sb.append(getValue(accelerationPedal,2));
|
||||
// 制动踏板行程值
|
||||
|
@ -311,7 +311,7 @@ public class VehicleData {
|
|||
//电机电流
|
||||
sb.append(getValue(motorCurrent,8));
|
||||
//动力电池剩余电量SOC
|
||||
sb.append(getValue(remainingBattery.toString(),6));
|
||||
sb.append(getValue(remainingBattery == null ? "" : remainingBattery.toString(),6));
|
||||
//当前状态允许的最大反馈功率
|
||||
sb.append(getValue(maximumFeedbackPower,6));
|
||||
//当前状态允许最大放电功率
|
||||
|
@ -370,6 +370,9 @@ public class VehicleData {
|
|||
}
|
||||
|
||||
public String getValue(String val , int valLength){
|
||||
if(val == null){
|
||||
val = "";
|
||||
}
|
||||
int length = val.length();
|
||||
if (length > valLength){
|
||||
return val.substring( 0 , valLength);
|
||||
|
|
|
@ -25,9 +25,10 @@ public class VehicleThread implements Runnable {
|
|||
public void run() {
|
||||
if (!isStop){
|
||||
if (!isPaused){
|
||||
log.info("{} - 模拟数据", this.vehicleInstance.getVin());
|
||||
log.info("{} - 上报数据", this.vehicleInstance.getVin());
|
||||
this.vehicleInstance.sendMsg(String.format("%s - 上报数据", this.vehicleInstance.getVin()));
|
||||
this.vehicleInstance.sendMsg(
|
||||
String.format("%s - 上报数据: %s", this.vehicleInstance.getVin(), this.vehicleInstance.getVehicleData().getMsg())
|
||||
);
|
||||
}else {
|
||||
log.info("暂停模拟和上报:[{}]", this.vehicleInstance.getVin());
|
||||
}
|
||||
|
@ -49,9 +50,6 @@ public class VehicleThread implements Runnable {
|
|||
*/
|
||||
public void resume() {
|
||||
isPaused = false;
|
||||
synchronized (this) {
|
||||
notify(); // 唤醒线程
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue