Scheduler - Time Based Tasks and Compensating for Lag

Discussion in 'Plugin Development' started by EdGruberman, Jan 28, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    EdGruberman Retired Staff

    Does anyone have a good idea for a way to compensate for resource lag which causes ticks to be slower?

    For instance, if I determine a task should run at 7:15 and at 7:00 I schedule it to run in 18,000 ticks (15mins * 60secs * 20ticks) but then the server lags and ticks happen at less than 20/second during that 15 minute period, the task will run later than 7:15.

    Here is an example of such where the task ended up running at 7:24, which is 9 mins late:
    I figure I might be able to do something where a task runs every 20 ticks and checks if something is due to run, but that just seems excessive. Is there a smarter way I'm overlooking?
  2. Offline


    This MIGHT work, but it could freeze/crash your server.
    2. ...
    3. Thread t = new Thread(new DelayedThing);
    4. t.start();

    2. public class DelayedThing extends Thread
    3. {
    4. public void run()
    5. {
    6. try
    7. {
    8. sleep(1000);//1000 milliseconds, so 1000*seconds for more configurability
    9. }
    10. //do something
    11. @SuppressWarnings("deprecation")
    12. stop();//stop this thread, to prevent it from running again/or to save system resources
    13. }
    14. }
Thread Status:
Not open for further replies.

Share This Page