0 Replies Latest reply on Nov 26, 2014 6:03 PM by javier Bartolome

    trimer into one cluster execute only one. please help

    javier Bartolome Newbie

      hello

      i have one cluster with 2 machines and into machine one jboss as 7.2 instance

      i have made one timer into EJB 3.1

      i hace one problem.

      whe it runs runs into the two instances.

      how can i controle the execution, onli one?

      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;

       

      @Singleton

      public class MyTimerBean  {

       

          @Resource

          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");

          }

          @Timeout

          public void programmaticTimeout(Timer timer) {

              this.setLastProgrammaticTimeout(new Date());

              System.out.println("timeout..");

          }

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

          public void automaticTimeout() {

              this.setLastAutomaticTimeout(new Date());

              System.out.println("Timeout.........");

          }

          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;

          }

      }