I need some help please, or suggestions on how to solve this problem.
I have data stored in a HashMap as below:
There is one producer per key and for example 100 users per key.
Currently I am synchronizing on the entire collection, and I guess this is not optimal, especially since Object(A/B/C) is going to change
very often, up to 5 times a second. And the clients really want the data as fast as possible.
Is it possible to sync on the KEY? is there perhaps a better collection to use?
Or what is the best way to solve this one without moving away from servlets?
Your data structure choice depends on size and dynamics (add, find, remove, etc.)
that you don't describe. As for synchronization, all users of a referenced item must be
protected from untimely changes to that item. So if user37 reads or updates the object
referenced by Key1, user37 must synchronize on that object, not the entire data structure.
In addition, users that use or change the data structure must synchronize on it.