If possible, use the support of your application server for this, if possible (some of them are, and some are not). For example, we use JBoss support for "HA Singleton", which is a service that runs only on the main cluster node. This is not ideal (you have to deal with the case when his brain farts from time to time), but he is good enough.
Otherwise, you can create something using JGroups, which provides automatic discovery and coordination of the cluster node, but this is not trivial.
As a last resort, you can use database locks to manage single-user clusters, but this is seriously fragile. Not recommended.
As an alternative to a singleton cluster, you can use a distributed cache. I recommend JBossCache (no JBoss application server is required to run) or EhCache (which now provides a distribution mechanism). You will have to reorganize your cache to work in a distributed way (it wonโt work magically), but it will probably be a better solution than a cluster singleton.
skaffman Jul 28 '09 at 13:38 2009-07-28 13:38
source share