0

I am trying to create ConcurrentHashMap<String,ConcurrentHashMap<String,String>> from list using parallel stream.it seems its going into infinite loop or deadlock and never coming out this code. let me if i hv missed something.

lines are like
L1|O1,O2,O3
L2|O1,O2,O3

ConcurrentHashMap<String, ConcurrentHashMap<String, String>> all= (ConcurrentHashMap<String, ConcurrentHashMap<String, String>>) lines
.parallelStream()
.collect(Collectors.toConcurrentMap(line->line.split("\\|")[0],line->{
     return (ConcurrentHashMap<String, String>)Arrays.asList(line.split("\\|")[1].split("\\s*,\\s*"))
     .stream().collect(Collectors.toConcurrentMap(l->l,l->"400"));
}));
shmosel
  • 49,289
  • 6
  • 73
  • 138
Rahul Kumar
  • 138
  • 1
  • 11
  • 1
    Works for me: http://ideone.com/exQRwm – shmosel Jul 10 '17 at 07:29
  • 1
    Btw, you're making a dangerous assumption by casting the result to `ConcurrentHashMap`. If you want a concrete type, use [the overload that accepts a map `Supplier`](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Collectors.html#toConcurrentMap-java.util.function.Function-java.util.function.Function-java.util.function.BinaryOperator-java.util.function.Supplier-). – shmosel Jul 10 '17 at 07:33
  • yes, But if you put your code in static block. then its not working. could you see once? static{ } – Rahul Kumar Jul 10 '17 at 07:44
  • Hmm, very interesting: http://ideone.com/uMtHu7 – shmosel Jul 10 '17 at 07:49
  • 1
    Yes its a duplicate. Thanks shmosel! – Rahul Kumar Jul 10 '17 at 07:59

0 Answers0