It seems that the only concurrent read/write operation is in the line shown above. But this operation can cause thread safe problem, for example:
- thread 1 clears domain map
- at this moment, OS suspends thread 1 an wakes up thread 2
- thread 2 calls getCandidateServicesToMatch, and got a empty domain list
The correct way may be making domains map a volatile reference (volatile may not be required), and use normal HashMap (no need to use ConcurrentHashMap because there is no concurrent read/write on this object), prepare new domains map and assign to this.domains on updating.
Similarly, services List in AbstractServicesManager has same problem of wrong usage of ConcurrentHashMap, but there is no thread safety problem because services list is assigned rather than "clean and putAll" on updating.
Please let me known if I had any misunderstanding of this machanism, thank you.