315157973 commented on pull request #9850: URL: https://github.com/apache/pulsar/pull/9850#issuecomment-793866931
> > `subscription_types_enabled` will create a new HashSet every time, which can be considered to be copy-on-write > > copy-on-write alone 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 (unless there is another way to ensure "safe publication"). The usage of Collections.unmodifiableSet wrapper 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". > > `subscription_types_enabled` will create a new HashSet every time, which can be considered to be copy-on-write > > copy-on-write alone 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 (unless there is another way to ensure "safe publication"). The usage of Collections.unmodifiableSet wrapper 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". You're right. Sorry, I missed some points. This Set will only add data when it is created, and it will only be read later. ---------------------------------------------------------------- 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]
