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.
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.
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.
You probably should read this solution to evaluate whether it fits your situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With