You can skip synchronization for the read access to that map if you make sure that all writes happen-before all reads. What it means is described in JLS 7 chapter 17.4.5.
In practice, you will have to make sure that the HashMap
is populated before any other threads that will access it are started and that its contents are not modified after that.
The reason this solution will work is that Thread.start()
call enforces a synchronization and therefore guarantees that all changes made prior to that call will be visible to both old and new threads after that call. Should you modify the object after that call this guarantee would be lost and a synchronized access would be necessary.