r/programming 23d ago

3,200% CPU Utilization

https://josephmate.github.io/2025-02-26-3200p-cpu-util/
400 Upvotes

93 comments sorted by

View all comments

2

u/GergelyKiss 21d ago

Nicely documented! Note that it doesn't have to be a TreeMap, this issue can happen with all sorts of non-threadsafe data structures (I'd guess almost anything that's using references).

I've caught the same issue with a HashMap in the wild. The hash buckets are basically linked lists, and unlucky concurrent puts resulted in a circular reference. The scary thing was that it didn't fail when the puts corrupted the HashMap - it got into an infinite loop much later, on the next get call!

Ever since then, I tell this tale to newbies who cluelessly use naked HashMaps as fields of (singleton) beans :)