xichen01 commented on PR #9185:
URL: https://github.com/apache/ozone/pull/9185#issuecomment-3548694280

   @sumitagrawl 
   
   > fixed_rate: after current iteration for getting blocks, it will wait for 1 
min for next iteration and schedule again. (This is existing implementation and 
default for new implementation). This is already solving the issue in existing 
code.
   
   The current implementation does not execute in this way, it will not wait 
for 1 min for next iteration, it might not wait and would proceed directly to 
the next iteration.
   
   The current `BackgroundService` executes `PeriodicalTask#run` via 
`scheduleWithFixedDelay`.
   `PeriodicalTask#run` does not execute the task directly but instead uses 
`CompletableFuture.runAsync`.
   Therefore, `scheduleWithFixedDelay` only submits the task according to a 
fixed delay; the task itself will not execute according to the fixed delay. 
   So, If the previous task takes 10 seconds, the next task will execute after 
50 seconds. If the previous task takes 60 seconds, the next task will execute 
immediately.
   
   you can add this test into `TestBackgroundService` to observe the output
   
   ```java
   @Test
     @Timeout(60)
     public void testSchedulingIntervalWithLongRunningTasks() throws 
InterruptedException {
   
       backgroundService = new BackgroundService(
           "TimingTestService", 3, TimeUnit.SECONDS, 1, 60) {
         @Override
         public BackgroundTaskQueue getTasks() {
           BackgroundTaskQueue newQueue = new BackgroundTaskQueue();
   
           newQueue.add(() -> {
             System.out.printf("%n[%s] Task start%n", 
Time.formatTime(System.currentTimeMillis()));
             Thread.sleep(5_000);
             System.out.printf("[%s] Task end%n", 
Time.formatTime(System.currentTimeMillis()));
             return BackgroundTaskResult.EmptyTaskResult.newResult();
           });
   
           return newQueue;
         }
       };
   
       backgroundService.start();
       Thread.sleep(60_000);
       backgroundService.shutdown();
     }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to