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.
4 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.
Keep in mind that EJB 3.1 offers new features that might help you do what you want, but this is WAS 8 only.

- 10,962
- 3
- 39
- 52
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.

- 31
- 2
may be you can use terracotta / ehcache locking? http://www.ehcache.org/documentation/2.4/terracotta/explicit-locking

- 6,879
- 2
- 56
- 59