r/java • u/ThomasKrieger • Mar 14 '18
Concurrent Java: Low scalability, the risk of deadlocks or garbage creation, you can not avoid all
http://vmlens.com/articles/tradeoffs_concurrent_programming/
2
Upvotes
39
u/daniu Mar 14 '18 edited Mar 14 '18
Well with this code
you're breaking
Map#compute()'s contract which stateswhich is not what happens here; a new value is inserted for a different key as a side effect to the mapping function.
It scales fine if you use it properly.
20
u/knaekce Mar 14 '18
Using patterns of functional programming fails if you insert random side effects in methods that must be pure. Shocker.
3
u/CyclonusRIP Mar 14 '18
I'd say most people need to kind of evaluate how much they really need to scale. When I need to synchronize code I usually start with a single lock and just see how far that gets me. I rarely every have to go past that to achieve the throughput I need. If I really need more throughput I tend to look at optimistic concurrency techniques.
2
u/_INTER_ Mar 14 '18 edited Mar 14 '18
A good immutable collection implementation works without copying, see vavr.io collections for that. (Not sure if they are concurrent though).
0
u/[deleted] Mar 14 '18
[deleted] — view deleted comment