@Datapublic class PropertiesMessage implements Cloneable, Serializable { public Map<String, DeviceProperties> propertiesMap; @Override public PropertiesMessage clone() throws CloneNotSupportedException { return (PropertiesMessage) super.clone(); }}@Datapublic class DeviceProperties implements Cloneable, Serializable { public String value; @Override public DeviceProperties clone() throws CloneNotSupportedException { return (DeviceProperties) super.clone(); }}@RequiredArgsConstructor(onConstructor = @(@Autowired))public class StorageListen { private static PropertiesMessage filteredRealtimeData = new PropertiesMessage(); private PeriodStorage periodStorage; @Scheduled(cron="*/1 * * * * ?") @Async("PeriodStorage") public void periodStorage() throws CloneNotSupportedException { PropertiesMessage clone = filteredRealtimeData.clone(); Map<String,List<StorageConfig>> map = new HashMap(); List<StorageConfig> list = new ArrayList(); StorageConfig s1 = new StorageConfig(); s1.setValue("1"); StorageConfig s2 = new StorageConfig(); s2.setValue("1"); list.add(s1); list.add(s2); map.put("1",list); periodStorage.storageData(clone,map); }}@RequiredArgsConstructor(onConstructor = @(@Autowired))public class PeriodStorage { private static DeviceProperties filteredRealtimeData = new DeviceProperties(); public void storageData(PropertiesMessage message, Map<String,List<StorageConfig>> map) throws CloneNotSupportedException { map.entrySet().stream().forEach(k -> { k.getValue().parallelStream().forEach(y -> { DeviceProperties clone = filteredRealtimeData.clone(); System.out.println(y.toString()); System.out.println(clone.toString()); }) }); }}
时间: 2024-04-25 17:27:56 浏览: 138
详解java中的深拷贝和浅拷贝(clone()方法的重写、使用序列化实现真正的深拷贝)
这些Java类和方法看起来是在进行数据存储和克隆的操作。其中,`PropertiesMessage`类包含一个`Map`,其中键是字符串,值是`DeviceProperties`对象。`DeviceProperties`类包含一个字符串值。`StorageListen`类使用定时任务调用`periodStorage`方法,该方法克隆`filteredRealtimeData`对象并将其传递给`storageData`方法。`PeriodStorage`类的`storageData`方法使用`map`参数进行迭代,并将其值传递给`DeviceProperties`对象的`clone`方法进行克隆。最后,该方法打印出每个`StorageConfig`对象和克隆`DeviceProperties`对象的字符串表示形式。
阅读全文