Use parallelStream foreach to create HashMap, But sometimes value is empty

后端 未结 1 1969
春和景丽
春和景丽 2021-01-15 02:30

Java Code Like :

List DbDetails = ... Like 50000 rows records
Map> details = new HashMap();

DbDetails .parallel         


        
1条回答
  •  天涯浪人
    2021-01-15 03:26

    HashMap is not thread-safe, so don't use parallel streams with it.

    Besides, why do that there, when streams can do it for you?

    DbDetails.parallelStream().collect(Collectors.groupingBy(Detail::getId))
    

    0 讨论(0)
提交回复
热议问题