master
dongzeliang 2023-11-17 09:00:00 +08:00
parent 353d3d63ab
commit 8bf6dd1e34
5 changed files with 149 additions and 1356 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,11 @@
package com.muyu.vehicle.core;
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.Map;
/**
* @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){
String vin = vehicle.getVin();
VehicleData vehicleData = vehicleDataMap.get(vin);
if (vehicleData == null){
vehicleDataMap.put(vin,VehicleData.vehicleBuild(vehicle));
VehicleInstance vehicleInstance = vehicleDataMap.get(vin);
if (vehicleInstance == null){
vehicleDataMap.put(vin,
VehicleInstance.builder()
.vehicleData(VehicleData.vehicleBuild(vehicle))
.vehicle(vehicle)
.build()
);
}
}

View File

@ -1,17 +1,14 @@
package com.muyu.vehicle.core;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.domain.Vehicle;
import com.muyu.service.VehicleService;
import com.muyu.vehicle.VehicleData;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.util.List;
/**

View File

@ -1,4 +1,4 @@
package com.muyu.vehicle;
package com.muyu.vehicle.model;
import com.muyu.domain.Vehicle;

View File

@ -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();
}
}