It is really surprising how many people ignore thread safety by justifying their incorrect solutions by saying “this thing is working, there are no issues and complains and it is fast”.
I’ve just encountered this kind of situation: a HashMap was used in a multithreaded environment where at any time following threads set could access it:
– at most one thread that was modifying the HashMap structurally
– some number of threads that were accessing the HashMap in read-only operations
Though I couldn’t reproduce any errors in this scenario using a HashMap in such a context is just invalid (believe me, M.Sc. in Computer Science, software engineering). When digging the case I found following interesting article: Java 7: HashMap vs ConcurrentHashMap
Moreover it presents ConcurrentHashMap data structure and presents some performance reports. I noticed people are afraid of this class because they suspect it is not fast enough. The above article shows ConcurrentHashMap is much more better than one could assume.
Another article showing ConcurrentHashMap is not only correct but also a fast solution: INFORMIT, Java Reference Guide: ConcurrentHashMap