描述:取出 cp中非 DataTime,下面代码是否合理,是否存在对deviceDataMap 并发问题?
Map<String,Map<String,String>> deviceDataMap = new HashMap<>();
String cp = "DataTime=20040506010101;SB1-RT=1.1;SB2-RT=2.1";
List<String> cpValusList = Arrays.asList(cp.split(";"));
cpValusList.stream().filter(item -> !item.contains("DataTime=")).forEach(item ->{
String deviceId = item.substring(0,item.indexOf("-"));
if(!deviceDataMap.containsKey(deviceId)){
Map<String,String> oneDeviceIdValusMap = new HashMap<>();
List<String> deviceIdValueList = Arrays.asList(item.split(","));
deviceIdValueList.forEach(value->{
String[] temp = value.split("=");
oneDeviceIdValusMap.put(temp[0], temp[1]);
});
deviceDataMap.put(deviceId, oneDeviceIdValusMap);
}
});
并行流就是一个把内容分成多个数据块,并用不不同的线程分别处理每个数据块的流
上面代码应该不存在并发问题,看样还是对java8 stream的原理没搞明白啊》》》》http://blog.csdn.net/sunjin94...