Changing the remaining time of a scheduler?

Discussion in 'Plugin Development' started by stelar7, Aug 13, 2012.

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

    stelar7

    Is there a way to change the remaining time until a scheduler starts?
     
  2. Offline

    desht

    I assume you're referring to a sync (or indeed async) delayed task?

    If so, not directly - but you could store the task id you got from the original scheduling, and when you want to reschedule the task, cancel the original task via the stored task id, and schedule a new task with the same runnable code. The complication being that you'd probably also need to store copies of any variables that the original runnable was using so that you could ensure the rescheduled task runs identically...

    The clean way to do it is with a custom class which encapsulates your runnable code along with all of the data that it needs, and the scheduler task ID. Then it become easy to add a method to that class which cancels and re-adds the task as needed.
     
  3. Offline

    Courier

    You don't really need to use a custom class.
    Code:java
    1. private Runnable myTaskRunnable;
    2. private int myId;
    3. private void reschedule(int ticks)
    4. {
    5. //cancel the event
    6. //reschedule myTaskRunnable
    7. }
    8. private void schedule(SomeEventOrSomething data)
    9. {
    10. this.myTaskRunnable = /*however you were making your runnable before... probably anonymous inner*/;
    11. //schedule myClassRunnable and get id
    12. }
     
  4. Offline

    stelar7

    say I start an asyncRepeaingTask with a delay of 1 hour, but after a while i want check the remaining time to make sure that is stays with a 1 hour delay, then change it to compensate for the delay
     
Thread Status:
Not open for further replies.

Share This Page