News for hackers. Stuff that matters.
Re:JVM Anatomy Quarks by sk5t on Friday January 31, 2020 @09:53AM (#22202084)
Yeah--mucking about with .intern for no good reason, or locking on strings in general, shouldn't pass a code review, this reeks of sticking one's fingers in all sorts of places they don't belong. ConcurrentHashMap.computeIfAbsent (and computing a value that is _not_ subject to mysterious external forces) is so much better.
Re:JVM Anatomy Quarks by xxs on Friday January 31, 2020 @11:21AM (#22202853)
>ConcurrentHashMap.computeIfAbsent

It's leak prone as it'd hold the references forever. It's a cheap and easy way to do it but far from ideal. I'd not recommend it.

Re:JVM Anatomy Quarks by sk5t on Friday January 31, 2020 @08:05PM (#22207738)
This seems a strange criticism--of course entries in a map don't disappear for no reason at all. Consider using an atomic cache if you are going to stick so many keys into the map that it becomes an issue. Or else bucket the keys into a known set, if you can tolerate the occasional collision.
Re:JVM Anatomy Quarks by xxs on Saturday February 01, 2020 @05:19AM (#22209768)
String.intern does remove references (it used not to and it was considered a major issue). Imagine parsing documents and keeping the words - it works well as long as the input is not malicious. Otherwise words would pile up with no one cleaning them, give it enough time/input to slow the application due to memory pressure, crashing with OOM.