Java:更改堆上的对象引用?
想知道是否有办法更改其他对象正在引用的堆上的对象。
我特别想做的是管理我的瞬态配置。我正在做的是从 JAXB 或 JPA 加载“绑定”配置。我有一个管理器,它维护一些线程来检查这些配置存储是否发生变化。如果这样做,我希望再次从存储中加载配置(创建配置的新实例)并用堆上的新配置实例替换“陈旧”配置实例,因此引用配置数据的任何对象都将获得最新的。
我知道我可能会遇到必须处理分层对象引用的噩梦 - 但我只是想了解各种潜在的方法,然后再决定简单地记录不创建本地引用并始终从配置管理器调用如果您期待最新的 =)
有什么想法如何做到这一点吗?我对 AOP 不太熟悉...但据我所知...我认为这可能提供实现这一目标的途径。
当然,欢迎任何其他想法=)
史蒂夫
Wondering if there is a way to change the object on the heap that other objects are referencing.
What I am specifically trying to do is manage my transient configuration. What I am doing is loading "bound" configuration from JAXB or JPA. I have a manager which maintains some threads to check if those config stores change. If they do, I wish to load the configuration from the store again (creates a new instance of the config) and REPLACE the "stale" configuration instance with the new one on the heap, so any objects referencing the configuration data will get the latest.
I understand I'll likely be running into a nightmare with having to deal with the hierarchical object references - but I simply want to learn about the various potential approaches before I decide to simply document not to create local reference and always call from the config manager if you expect the latest =)
Any ideas how to do this? I'm not too familiar with AOP...but from what I know about it...I am thinking this might provide an avenue to achieve this.
Any other ideas are welcome, of course =)
Steve
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 JAXB 或 JPA 一无所知,但这就是我要做的。为您的各种对象提供对配置包装器的引用。然后,您可以更新配置(以同步方式),而无需更改这些引用:
然后您只需分发 ConfigWrapper 的实例,并且可以在需要时自由地重新分配支持对象。
I don't know anything about JAXB or JPA, but here's what I'd do. Give your various objects a reference to a wrapper for the config. Then you can update the config (in a synchronized manner) without needing to change those references:
Then you would only distribute the instance of ConfigWrapper, and can freely reassign the backing object whenever you want.
您可以查看 Spring 框架。如果我没记错的话,它支持类似的东西(也许 this< /a>?)。
You can check out the Spring framework. If my memory serves, it supports something like that (maybe this?).