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 hashmap pops up before any other threads that access it and its contents are not modified after it.

The reason this solution will work is that 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

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -