0 Replies Latest reply on Nov 26, 2014 11:04 PM by javier Bartolome

    timer into one cluster. control the execution for only one instance

    javier Bartolome Newbie


      i have one cluster with 2 machines and into each machine one jboss EAP 6.2 instance

      i have made one timer into EJB 3.1

      i hace one problem.

      when i deploy the EJB (Timer) it runs runs into the two instances at the same time

      how can i controle the execution, only into  one machine?

      if it runs, without control, into the two machines the processes are runs twice.


      can you help me?

      my code is:


      import java.util.Date;

      import javax.annotation.Resource;

      import javax.ejb.Schedule;

      import javax.ejb.Singleton;

      import javax.ejb.Timeout;

      import javax.ejb.Timer;

      import javax.ejb.TimerService;



      public class MyTimerBean  {



          TimerService timerService;

          private Date lastProgrammaticTimeout;

          private Date lastAutomaticTimeout;


          @Schedule(second="*/10", minute="*",hour="*", persistent=false)

          public void doWork(){

              System.out.println("timer:**runs each 10");


          public void setTimer(long intervalDuration) {

              System.out.println("Setting a programmatic timeout for  intervalDuration  milliseconds from now.");

              Timer timer = timerService.createTimer(intervalDuration, "Created new programmatic timer");


              //cada 20 segundos

          @Schedule(second="*/20", minute="*",hour="*", persistent=false)

          public void miLanzamiento(){

          System.out.println("====runs each 20");



          public void programmaticTimeout(Timer timer) {

              this.setLastProgrammaticTimeout(new Date());



          @Schedule(minute="*/3", hour="*")

          public void automaticTimeout() {

              this.setLastAutomaticTimeout(new Date());



          public String getLastProgrammaticTimeout() {

              if (lastProgrammaticTimeout != null) {

                  return lastProgrammaticTimeout.toString();

              } else {

                  return "never";




          public void setLastProgrammaticTimeout(Date lastTimeout) {

              this.lastProgrammaticTimeout = lastTimeout;


          public String getLastAutomaticTimeout() {

              if (lastAutomaticTimeout != null) {

                  return lastAutomaticTimeout.toString();

              } else {

                  return "never";



          public void setLastAutomaticTimeout(Date lastAutomaticTimeout) {

              this.lastAutomaticTimeout = lastAutomaticTimeout;