Question

I need to run some business logic once and only once in a Geronimo/Tomcat cluster when a WAR (or EAR) deploys and before the applications starts serving to users.

The way I've been doing this has been to-date has been ad-hoc and is not fault tolerant. I use a configuration file on node 1 and designate it the "startup node". When the application starts up in the cluster, every node writes its ip address to a database and then sleep-waits in a Servlet.init that was set to load-on-startup in web.xml. When the startup node sees that all expected nodes have written their IP to the database, it runs the business logic. When the startup business logic completes, it sends the all-clear to the other nodes by writing a confirmation row to the database.

All of the non-startup nodes periodically (twice a second) poll the database for this all-clear signal, and when they see it, they finish their startup and return from Servlet.init. At this point all of the nodes serve the application normally to users.

I haven't had my startup logic fail yet, but I was wondering if there was some Java EE standard or robust 3rd party library approach to running my startup logic only once across my cluster. Thanks!

Edit 2013/07/21: I recalled that WebLogic Server had sophisticated startup facilities that might be useful in achieving the "init only once in the cluster" logic that I want to do in my Geronimo/Tomcat cluster. I did some digging and yes, WebLogic can do exactly what I want! Here is a great article on the subject: http://developsimpler.blogspot.com/2012/03/weblogic-clusters-and-singleton-service.html

I cannot afford WebLogic, unfortunately. So, is there anything similar in Geronimo or Tomcat (or other open source Java EE servers?) Or, are there 3rd party libraries I might use to achieve the same thing?

Was it helpful?

Solution

For distributed coordination, there are tools like Zookeeper.

I don't think there is a Java EE standard for what you are looking for and I can't understand such an usecase, can you describe why you want 1 single "master" app to wait for other applications to startup?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top