Thread safety - reading mutable objects (java) -
I have a shared resource - a simple POJO that wraps a hashmap - which will start once on startup and then Only ever read, maybe together, by many threads (context is a web application) Do I need to synchronize access to the object (or alternatively using a concurrent hashp) or is it safe to read many simultaneous? Will synchronizing add important overhead?
If you are certain that you can skip synchronization for access to that map read that all Writes yes-before everyone reads what it means. In practice, you have to make sure that The reason this solution will work is that hashmap pops up before any other threads that access it and its contents are not modified after it.
threads. Start () calls apply a synchronization and therefore guarantees that all changes made before that call will appear After both old and new threads you should modify the object after that call, this guarantee will be lost and a synchronized access will be required.
Comments
Post a Comment