Occasionally a solution needs a singleton in a cluster.  For example, if you have three identical applications in a cluster, only one of the servers should generate the nightly reports.

The first option would be to use a JNDI flag but this can be useless if the server goes due to a power outage without first clearing the JNDI flag.

The second option would be to use JINI to automatically start up a new process if the first fails but it adds a level of complexity that will not be understood by most developers (JINI never really took off).  JINI too requires broadcast across the network which may not be available on customer networks.

Option three would be to use a heartbeat mechanism to identify who is the owner of the right to run the nightly report.  This mechanism would update a database record with a new value.  If the value did not update for too long, another server would take control of the database record.  A clustered memory storage like eHcache could be used instead of a database.

blog comments powered by Disqus