master
parent
353d3d63ab
commit
8bf6dd1e34
File diff suppressed because it is too large
Load Diff
|
@ -1,9 +1,11 @@
|
||||||
package com.muyu.vehicle.core;
|
package com.muyu.vehicle.core;
|
||||||
|
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
import com.muyu.vehicle.VehicleData;
|
import com.muyu.vehicle.model.VehicleData;
|
||||||
|
import com.muyu.vehicle.model.VehicleInstance;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author DongZl
|
* @author DongZl
|
||||||
|
@ -15,7 +17,7 @@ public class LocalContainer {
|
||||||
/**
|
/**
|
||||||
* 车辆容器
|
* 车辆容器
|
||||||
*/
|
*/
|
||||||
public static final HashMap<String, VehicleData> vehicleDataMap = new HashMap<>();
|
public static final Map<String, VehicleInstance> vehicleDataMap = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加车辆
|
* 添加车辆
|
||||||
|
@ -23,9 +25,14 @@ public class LocalContainer {
|
||||||
*/
|
*/
|
||||||
public static void setVehicle(Vehicle vehicle){
|
public static void setVehicle(Vehicle vehicle){
|
||||||
String vin = vehicle.getVin();
|
String vin = vehicle.getVin();
|
||||||
VehicleData vehicleData = vehicleDataMap.get(vin);
|
VehicleInstance vehicleInstance = vehicleDataMap.get(vin);
|
||||||
if (vehicleData == null){
|
if (vehicleInstance == null){
|
||||||
vehicleDataMap.put(vin,VehicleData.vehicleBuild(vehicle));
|
vehicleDataMap.put(vin,
|
||||||
|
VehicleInstance.builder()
|
||||||
|
.vehicleData(VehicleData.vehicleBuild(vehicle))
|
||||||
|
.vehicle(vehicle)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
package com.muyu.vehicle.core;
|
package com.muyu.vehicle.core;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
||||||
import com.muyu.service.VehicleService;
|
import com.muyu.service.VehicleService;
|
||||||
import com.muyu.vehicle.VehicleData;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.muyu.vehicle;
|
package com.muyu.vehicle.model;
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.domain.Vehicle;
|
import com.muyu.domain.Vehicle;
|
|
@ -0,0 +1,80 @@
|
||||||
|
package com.muyu.vehicle.model;
|
||||||
|
|
||||||
|
import com.muyu.domain.Vehicle;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZeLiang
|
||||||
|
* @version 1.0
|
||||||
|
* @description 车辆实例
|
||||||
|
* @date 2023/11/16
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class VehicleInstance {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车辆
|
||||||
|
*/
|
||||||
|
private Vehicle vehicle;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实例数据
|
||||||
|
*/
|
||||||
|
private VehicleData vehicleData;
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
|
|
||||||
|
Thread thread = new Thread(() -> {
|
||||||
|
while (true){
|
||||||
|
try {
|
||||||
|
sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
System.out.println(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
System.out.println("执行了五秒,等待五秒,在开始");
|
||||||
|
try {
|
||||||
|
synchronized (thread){
|
||||||
|
thread.wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
System.out.println("等待了五秒,现在开始,3秒后杀死");
|
||||||
|
synchronized (thread){
|
||||||
|
thread.notify();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sleep(3000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
synchronized (thread){
|
||||||
|
thread.interrupt();
|
||||||
|
}
|
||||||
|
System.out.println("停止成功" + thread.isAlive());
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue