Hi guys. I'm studying for ocp8 exam from OCP study guide of jeanne and scott chapter 7 about Concurrency.
I'm gonna transcribe what the books says:
Given: service.scheduleAtFixedRate(command, 5, 1, TimeUnit.MINUTES);
This example executes a Runnable task every minute, following an initial five-minute delay
One risk of using this method is the possibility a task could consistently take longer to run than the period between tasks.
Up to here what I understand is that for example in this case on the first minute a task is created and submitted and then it's gonna take 5 minutes to be executed. And in the minute number two ( while the first task is on delaying) another task is submitted and so on.
What would happen if the task consistently took five minutes to execute?
Despite the fact that the task is still running, the ScheduledExecutorService would submit a new task to be started every minute.
-> And now what I'm not understandying:
If a single thread executor was used, over time this would result in endless set tasks being scheduled, which would run back to back assuming that no other tasks were submitted to the ScheduledExecutorService.
Especially I can't totally undertand the following: "this would result in endless set tasks being scheduled, which would run back to back assuming that no other tasks were submitted"
I can guess that a stack of tasks would be piled up as if there was not every minute a new task being submitted.