Search code examples
jakarta-eewebsphereejb

WAS EJB Schedule persistent timer in clustered environment


I want to check my understanding of how to program a timer in a WebSphere Application Server clustered environment, which will trigger once across the whole cluster (instead of on each cluster member where the application is deployed).

I have a scheduler in my EJB code as follows:

@Stateless
public class TestTimer {
@Schedule(second="*/10", minute="*", hour="8-23", dayOfWeek="Mon-Fri",
      dayOfMonth="*", month="*", year="*", info="TestTimer", persistent=true)
    public void scheduledTimeout(final Timer t) {
        System.out.println("@Schedule called at: " + new java.util.Date());       
   }
}

This appears to work out-of-the-box on a single instance, despite me not having configured anything in the Resources/Schedulers part of the WebSphere admin console.

So, how does WebSphere know where to persist my schedule to if I haven't given it a datasource to use? If this is all the configuration I do, will it be scheduled across the cluster (once I move to a clustered environment), or will this fire multiple times, once per each deployed instance? If the latter, how do I instead change my approach to only fire once across the whole cluster?

This answer (https://stackoverflow.com/a/49430454/318414) says I need "all of the cluster members [to] have [an] EJB Container configuration that points to the same cluster scoped Scheduler" - how do I do that?


Solution

  • By default, the EJB Container uses an internally provided server scoped Scheduler that stores persistent timers in a local derby database that is automatically created for you as needed.

    In order to have the timers run on only one server in the cluster, all of the cluster members must share a single database and use a cluster scoped Scheduler that will then coordinate access to the shared database across all cluster members.

    The instruction for creating a Scheduler may be found here: https://www.ibm.com/docs/en/was-nd/8.5.5?topic=schedulers-configuring

    After creating a cell scoped scheduler that uses a database that is shared across all cluster members, then the EJB Container configuration to use that Scheduler is described here: https://www.ibm.com/docs/en/was-nd/8.5.5?topic=service-configuring-timer-network-deployment

    Note that the default derby database may not be shared across multiple servers; the default derby database does not include multi-client support. Attempting to use it with multiple concurrent clients will result in errors.