lhotari commented on pull request #9850: URL: https://github.com/apache/pulsar/pull/9850#issuecomment-793836429
> `subscription_types_enabled` will create a new HashSet every time, which can be considered to be copy-on-write copy-on-write isn't sufficient in Java since it could lead to "unsafe publication" where some values in the published reference aren't visible to the other thread ([safe publication explained](https://shipilev.net/blog/2014/safe-public-construction/#_safe_publication)). By googling a simple demonstration of the problem: https://gist.github.com/synther/2631238 . Sharing a HashSet to another thread requires the usage of Collections.unmodifiableSet wrapper. That ensures safe publication. This is explained in this SO answer: https://stackoverflow.com/a/5379941 Similarly, sharing a HashMap reference requires the usage of Collections.unmodifiableMap wrapper unless there is some other means to ensure "safe publication". ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
