Assuming the scheduler runs after every 5 seconds and the current task being executed takes 7 seconds.
i. Will the scheduler start another instance of the Task before the previous task finishes?
ii. How can I prevent a scheduler from starting an instance of a task before the previous once completes?
Code samples
val task = new Runnable { def run() { processBatch } }
You could use an actor to executie the task and have the scheduler sending a trigger message to that actor.
In any way, you will end up with a queue of things to be processed as execution of the task takes more time than the scheduler triggers them and that needs some thought (what happens after a crash)