Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Singletons with TimerManager on WebSphere Cluster

How can I get a timer task on a WebSphere cluster to execute once and only once? I know this is possible on other app servers but can't figure out how to do this in WebSphere.

like image 208
sujan Avatar asked May 12 '10 17:05

sujan


3 Answers

You can use WebSphere's Scheduler service to do what you want. If you define a scheduler service in the cluster scope, each cluster member will run a scheduler daemon but the tasks DB will be shared, meaning only one of them will perform the task you add. They poll the DB every 30 seconds (configurable) and the first on to see the task will perform it.

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.nd.doc/info/ae/ae/welc6tech_sch_adm.html

Keep in mind that EJB 3.1 offers new features that might help you do what you want, but this is WAS 8 only.

like image 164
Aviram Segal Avatar answered Oct 20 '22 21:10

Aviram Segal


I'm not sure if your problem is a cluster or something else. But if you want to stop a TimerListener after one execution you would just use the inputed timer variable and cancel it.

Ex:

public static class MyTimer implements TimerListener {
     public void timerExpired(Timer timer) {    
         timer.cancel();
     }
}

If you are having a problem with the cluster environment running the task once per instance than my apologies for posting this simple answer.

like image 23
Zach Avatar answered Oct 20 '22 22:10

Zach


You probably should read this solution to evaluate whether it fits your situation.

like image 2
erloewe Avatar answered Oct 20 '22 22:10

erloewe