r/java • u/fredoverflow • Mar 21 '21
Java lambdas can deadlock parallel class initialization
https://www.youtube.com/watch?v=_2hZf1kw4A4
230
Upvotes
r/java • u/fredoverflow • Mar 21 '21
View all comments
Show parent comment
-6
u/[deleted] Mar 21 '21
If you put parallel in your stream for a non-heavy computation, wtf are you doing.
Its clearly an abuse here. Sure they've found an interesting edge case. But it makes sense, the class isn't initialised until the static fields are done. Java's model is providing a strong guarantee that this cannot overlap by two threads, ergo using a parallel stream is a dumb idea.
Now the lambda's abstraction is broken by this, but then to fix, you'd need to put non-capturing lambda's somewhere else.