3 Replies Latest reply on May 23, 2017 1:24 PM by Radoslav Husar

    Timerservice is starting on both nodes in cluster when server start.

    Paresh Vasani Newbie

      Hi,

      I faced one issue:

       

      Timerservice is starting on both nodes in cluster when server start. It supposed to start at on one node and second node should not start timer service if it has been started at other node.

      Thank you very much for your guide. Also in cases of fail-over  timerservice is not replicated to other nodes.

       

      I have implemented Clustered Ejb3 timer. I have used JBOSS EAP 6.4.

      I have followed all mentioned steps. Server started successfully.

      On one of my application's "Http request" called timer service and have stated timer.

      with this code: see the start method below.. which I am calling with javax.ejb.Singleton instance of MyTimerServiceImpl.

      package com.mastercard.promotion.domain.service;

       

      import java.util.Date;

      import javax.annotation.Resource;

      import javax.ejb.ScheduleExpression;

      import javax.ejb.Singleton;

      import javax.ejb.Timeout;

      import javax.ejb.Timer;

      import javax.ejb.TimerConfig;

      import javax.ejb.TimerService;

      import javax.naming.InitialContext;

      import javax.naming.NamingException;

       

      /**

      * A simple example to demonstrate a implementation of a cluster-wide singleton timer.

      *

      * @author <a href="mailto:wfink@redhat.com">Wolf-Dieter Fink</a>

      */

      @Singleton

      public class DefaultMyTimerService implements MyTimerService {

       

        @Resource

        private TimerService timerService;

       

       

        @Timeout

        public void scheduler(Timer timer) {

        System.out.println("Timeout: Info=" + timer.getInfo());

        }

       

       

        @Override

        public void initialize(String info) {

        timerService.createIntervalTimer(new Date(), 8000, new TimerConfig(info, true));

        }

       

       

        @Override

        public void stop() {

        System.out.println("Stop all existing timers");

        for (Timer timer : timerService.getTimers()) {

        System.out.println("Stop timer: " + timer.getInfo());

        timer.cancel();

        }

        }

      }

      Getting timeout on every node.. can you please suggest what i need to configure for if timer is active on one node than timer service must not start on other node.

      Advance Thank you for your answer. Please reply