While using "scheduleAtFixedRate" method in com.smartfoxserver.v2.util.TaskScheduler, my scheduled tasks are getting overlapped as my first task is taking more than 2 seconds to complete and in the mean time my second task is getting started. The period argument in above mentioned method is set to "2 seconds" which executes the second task 2 seconds after first task is triggered no matter the first task is completed or not.
To prevent overlapping of tasks, fixed delay scheduler could help but com.smartfoxserver.v2.util.TaskScheduler class has a method only for fixed rate scheduler with name "scheduleAtFixedRate". Kindly help me by suggesting a possible solution to my problem which is compatible with SFS2X.
SFS TaskScheduler
Re: SFS TaskScheduler
Hello,
This is the expected behavior.
A task that is set to run after two seconds will be run exactly after two seconds. The scheduler is not supposed to run tasks in sequence, waiting for one task to complete before starting a new one.
It is essentially just a thread pool that runs tasks independently at the specified interval.
If you need to run tasks in sequence you have to schedule the first task and at the very end of that Task (in your Runnable class), schedule the next task that is supposed to be executed after the current one.
Hope it helps
dhruv0002 wrote:While using "scheduleAtFixedRate" method in com.smartfoxserver.v2.util.TaskScheduler, my scheduled tasks are getting overlapped as my first task is taking more than 2 seconds to complete and in the mean time my second task is getting started. The period argument in above mentioned method is set to "2 seconds" which executes the second task 2 seconds after first task is triggered no matter the first task is completed or not.
This is the expected behavior.
A task that is set to run after two seconds will be run exactly after two seconds. The scheduler is not supposed to run tasks in sequence, waiting for one task to complete before starting a new one.
It is essentially just a thread pool that runs tasks independently at the specified interval.
If you need to run tasks in sequence you have to schedule the first task and at the very end of that Task (in your Runnable class), schedule the next task that is supposed to be executed after the current one.
Hope it helps
Who is online
Users browsing this forum: No registered users and 62 guests