HashMap – Unintended consequence in Multi-threaded environment – HashMap Degeneration – How can it happen?

A HashMap is designed to build for only one purpose – hold key-value for a single threaded events. A map is very efficient for this purpose. However, you diverse from the fundamentals of why a HashMap exist, then you are charting into an extremely dangerous section of programming world – race condition, infinite loops that is basically Degeneration.

Thus, a simple hashmay in multi-threaded environment will cause one time to spin out of control. To avoid such pain in production, use synchronized HashMap in all your applications.

Refer to the blog post for the detail explanation on how a race condition in Hashmap can cause this issue of going into infinite loop.

Reference

  1. a good point on Race condication in Hashmap implimentation
  2. Hashmap degeneration is not a bug