Singletones with TimerManager in a WebSphere Cluster

How can I get a timer job in a WebSphere cluster to run once and only once? I know that this is possible on other application servers, but cannot figure out how to do this in WebSphere.

+7
java concurrency timer cluster-computing websphere
source share
4 answers

You can use the WebSphere Scheduler service to do what you want. If you define the scheduler service in the cluster area, each member of the cluster will start the scheduler daemon, but the task database will be divided, which means that only one of them will complete the task that you add. They poll the database every 30 seconds (configurable), and the first - to complete the task.

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 can help you do what you want, but it is only WAS 8.

+5
source share

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

Example:

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

If you have a problem with a cluster environment that runs a task once per instance, than my apologies for sending this simple answer.

+3
source share

You should probably read this decision to assess whether it is appropriate for your situation.

+2
source share

Perhaps you can use terracotta / ehcache lock? http://www.ehcache.org/documentation/2.4/terracotta/explicit-locking

0
source share

All Articles