Package com.yahoo.jrt

Class Task


  • public class Task
    extends java.lang.Object
    A Task enables a Runnable to be scheduled for execution in the transport thread some time in the future. Tasks are used internally to handle RPC timeouts. Use the TransportThread.createTask method to create a task associated with a Transport object. Note that Task execution is designed to be low-cost, so do not expect extreme accuracy. Also note that any tasks that are pending execution when the owning Transport object is shut down will never be run.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean kill()
      Cancel the execution of this task and make sure it can never be scheduled for execution again.
      void schedule​(double seconds)
      Schedule this task for execution.
      void scheduleNow()
      Schedule this task for execution as soon as possible.
      boolean unschedule()
      Cancel the execution of this task.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • schedule

        public void schedule​(double seconds)
        Schedule this task for execution. A task may be scheduled multiple times, but may only have a single pending execution time. Re-scheduling a task that is not yet run will move the execution time. If the task has already been executed, scheduling works just like if the task was never run.
        Parameters:
        seconds - the number of seconds until the task should be executed
        See Also:
        kill()
      • scheduleNow

        public void scheduleNow()
        Schedule this task for execution as soon as possible. This will result in the task being executed the next time the reactor loop inside the owning Transport object checks for tasks to run. If you have something that is even more urgent, or something you need to be executed even if the Transport is shut down, use the TransportThread.perform(java.lang.Runnable) method instead.
        See Also:
        kill()
      • unschedule

        public boolean unschedule()
        Cancel the execution of this task.
        Returns:
        true if the task was scheduled and we managed to avoid execution
      • kill

        public boolean kill()
        Cancel the execution of this task and make sure it can never be scheduled for execution again. After this method is invoked, invoking the schedule and scheduleNow methods will have no effect.
        Returns:
        true if the task was scheduled and we managed to avoid execution