How can we ensure that there is a single instance of a class in a clustered environment
How can we ensure that there is a 开发者_JAVA百科single instance of a class in a clustered environment? The class is Serializable.
You need to correctly implement readResolve method of your singleton class.
Preferably, I think terracotta would help.
This link has more help http://forums.terracotta.org/forums/posts/list/771.page
Use a container that provides application scoped singletons, e.g. Seam, Spring etc.
- Use container which provides you with this facility.
- If use of container is not a feasible option, then create a RemoteFactory which will provide you with instance of the class in context.
精彩评论