1 Reply Latest reply on Oct 27, 2008 1:43 PM by Gabriel Goïc

    Repeating asynchronous tasks fail silently

    Phil Haigh Novice


      I have been experiencing some issues with repeating asychronous tasks silently ceasing to repeat. Essentially it seems that if you have a method annotated Asynchronous and with parameters doStuff(@Duration Long waitBeforeStart, @IntervalDuration Long interval), if the method throws an uncaught exception, no further invocations of the method occur.

      I have created a simple test case.

      @In (required=false,create=true)
      private MaintenanceTasksI maintenanceTasks;
      public void scheduleRecurringTask()

      public interface MaintenanceTasksI
               @Destroy @Remove
               public abstract void destroy();
           public void doStuff(@Duration Long waitBeforeStart, @IntervalDuration Long interval);

      public class MaintenanceTasks implements MaintenanceTasksI
          @Destroy @Remove
          public void destroy() {}
           private Log log;
           public void doStuff(@Duration Long waitBeforeStart, @IntervalDuration Long interval)
                int x = new Random().nextInt(10);
                if (x>8)
                     throw new NullPointerException();

      The output from which is below:

      2008-10-23 15:03:04,130 [INFO  MaintenanceTasks] 6
      2008-10-23 15:03:06,119 [INFO  MaintenanceTasks] 5
      2008-10-23 15:03:08,119 [INFO  MaintenanceTasks] 2
      2008-10-23 15:03:10,118 [INFO  MaintenanceTasks] 8
      2008-10-23 15:03:12,117 [INFO  MaintenanceTasks] 2
      2008-10-23 15:03:14,117 [INFO  MaintenanceTasks] 9

      As you can see, the task happily repeats from startup every 2 seconds, until it encounters a random number higher than 8, in which case the forced NPE causes the task to stop executing, and no further instances invoked. Nor is the NPE logged by the container.

      If this is expected behaviour, what is the best design pattern to defend against this happening?