Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HashMap thread safe for multi-thread read-only operations?

807588Feb 10 2009 — edited Feb 10 2009
If I have a HashMap (initialized and loaded) via static initialization of the class and I never write to it or modify it again, it is thread-safe for multiple read-only threads? In other words, I don't need to use synchronization or a synchronized map, do I?

I believe I should be OK since the JVM handles the static initialization at class loading time, which is guaranteed to only happen once, so the mapping should be created in a thread-safe manner. From then on, if I only read from it I should be OK, right?

Thanks!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2009
Added on Feb 10 2009
12 comments
4,697 views