If the map is actively updating, you may have a race between containsKeyand get. Instead, you can write something like
list.parallelStream()
.filter(id -> {
Person person = map.get(id);
return person != null && !Strings.isNullOrEmpty(person.getName());
})
.collect(Collectors.toList());
Using parallelStreamhas nothing to do with it - it's great. He makes two separate calls in ConcurrentMapon the same key and expects them to have consistent results, which is the problem.
source
share