In java doc of this method, concurrency is not mentioned, so it seems that the 'set' method do not ensure visibility. I'm not sure about this.
In fact, I have encountered a difficulty because of this question. I'm going to build a distribute configuration platform based on zookeeper. Like the other configuration platform, if a field is annotated by a specific annotation, the platform will mapping this field to a node in zookeeper. Once the value of the mapped node is changed, project using this platform will be informed by zookeeper watcher and change the annotated field using reflection(by 'set' method).
The project using my configuration platform is likely to be a web application, which has one and only one object in service layer, so the field is always accessed in concurrency. if the 'set' method do not ensure visibility, do I must force the project add Keyword volatile for the annotated field ? I looks strange and tedious. Is there some better way about this problem ? How do the other configuration platforms solving this ?
Aucun commentaire:
Enregistrer un commentaire