1 2 Previous Next 18 Replies Latest reply: Jan 27, 2013 8:03 AM by Luiz Gustavo Go to original post RSS
      • 15. Re: TimerService: Timer interval stops after retry
        Wolf-Dieter Fink Master

        It's OpenSource

        You might check my changes in AS7 (follow the git pull request in the Jira).

        In AS6 you can simply find the class from the stacktrace (CalendarTimerTask.java:80) and you might fix this bug

        • 16. Re: TimerService: Timer interval stops after retry
          Dee Kay Newbie

          I stepped up to AS7 and noticed that some of the services i need aren't yet implemented.

          So finally i fixed the problem this way:

           

           

          @Singleton

          @LocalBean

          @TransactionManagement(TransactionManagementType.BEAN)

          public class BusinessTimerService {

           

              private final static int MAX_THREAD_TIME = 180;

              private PingThread businessThread = new BusinessLogicThread();

              private Date startTimestamp;

           

              private static class BusinessLogicThread extends Thread {

           

                  public void run() {

                      // Business logic

                  }

           

              }

           

              @Schedule(second="*/"+Constants.PING_DELAY, minute="*", hour="*", persistent=false)

              public void timeout() {

                  if(businessThread == null || !businessThread.isAlive()) {

                      startTimestamp= new Date();

                      businessThread = new BusinessLogicThread();

                      businessThread.start();

                  } else {

                      long executionTime = new Date().getTime() - startTimestamp.getTime();

                      if(executionTime > MAX_THREAD_TIME*1000) {

                          System.err.println("Exception: Thread execution time == "+executionTime+"ms. Timeout! Start a new thread!");

                          businessThread = null;

                      }

                  }

              }

           

          }

           

           

          After a 3-day-Stresstest i recommend this code-skeleton(and yes...i know....NULLing the thread after the user-defined timeout isn't the best way :-) )

           

           

           

          Regards

           

          Daniel

          • 17. Re: TimerService: Timer interval stops after retry
            Wolf-Dieter Fink Master

            Hi Daniel,

            you use your fix with AS6, right?

            I think you know that this solution violate the EJB spec because the Thread handling is not allowed.

            So it should be just a workaround and must be well tested, as you already done, for the specific application/JBoss installation!

             

            Also there is now a full certified AS7.1 (hurray ) in the download area http://download.jboss.org/jbossas/7.1/jboss-as-7.1.0.Final/jboss-as-7.1.0.Final.zip available.

            You may find here all what you need to migrate.

             

            regards

            Wolf

            • 18. Re: TimerService: Timer interval stops after retry
              Luiz Gustavo Newbie

              Hi,

               

               

              I had the same problem.

              In my case, the processing time is not known, just the timeout, so it is common the timeout occur before the processing finish.

              I could fix it with this simple workaround:

               

               

              @Startup

              @Singleton

              @TransactionManagement(TransactionManagementType.CONTAINER)

              public class SomeScheduledService implements SchedulableService{

               

                 

                  @Resource

                  private TimerService timerService;

                 

                  @Resource

                  private SessionContext context;

                 

                  private static boolean canExecute = true;   

                 

                  @Timeout

                  @Lock(LockType.READ)

                  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

                  public void run(Timer timer){

                     

                      if(SomeScheduledService.canExecute){

                         

                          try {

                                                         

                              SomeScheduledService.canExecute = false;

                             

                              // call important business services

                                 

                          } catch (Exception e) {

                             

                              // do something useful here

                             

                          } finally {

                             

                              SomeScheduledService.canExecute = true;

                             

                              // release resources       

                          }   

                     

                      } else{           

                          // sorry... I'm busy now... try again next timeout           

                      }       

                  }   

              }

               

               

              I hope it can help.

               

               

              Best Regards,

              Luiz Gustavo S. de Souza

              1 2 Previous Next