On Tue, 30 Nov 2021 20:50:53 GMT, Weijun Wang <wei...@openjdk.org> wrote:

> Consider this case, two threads are changing a value at the same time. Since 
> the method is not synchonized, thread1 might finish the first part of the 
> method (`super.replace`) earlier than thread2, but it finishes the second 
> part (`parseLegacy`) later than thread2. At the end, the internal entrySet 
> has thread2's value but the legacy map has thread1's value.

Well, then the synchronized keyword should be put on the public methods instead 
of the internal parseLegacy() method, no? Otherwise, the super.xxx() and the 
internal legacyMap may not updated in sync. The public methods did have the 
synchronized keywords which I removed since the putService() call isn't 
synchronized either (and it updates the serviceMap first and then stores the 
String-String mapping into super.xxx()). The main performance bottleneck is in 
getService(), so I can add back the "synchronized" keywords to other public 
methods if you are concerned.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6513

Reply via email to