Package com.yahoo.jrt
Class Task
- java.lang.Object
-
- com.yahoo.jrt.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 theTransportThread.createTask
method to create a task associated with aTransport
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 owningTransport
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.
-
-
-
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 owningTransport
object checks for tasks to run. If you have something that is even more urgent, or something you need to be executed even if theTransport
is shut down, use theTransportThread.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 theschedule
andscheduleNow
methods will have no effect.- Returns:
- true if the task was scheduled and we managed to avoid execution
-
-