views:

93

answers:

3

How can we ensure that there is a single instance of a class in a clustered environment? The class is Serializable.

+1  A: 

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

Gopi
+2  A: 

Use a container that provides application scoped singletons, e.g. Seam, Spring etc.

seanizer
How will that help in a cluster?
skaffman
obviously, your cluster has to run a single such container
seanizer
A: 
  1. Use container which provides you with this facility.
  2. If use of container is not a feasible option, then create a RemoteFactory which will provide you with instance of the class in context.
Tushar Tarkas