Class InstantRunnable

  • All Implemented Interfaces:
    TaskRunnable, Runnable
    Direct Known Subclasses:
    InstantGroupRunnable

    public class InstantRunnable
    extends GeneralTaskRunnable
    Instant task (task will only be run once) which has handler integrated (implements ScheduleableAction) can be scheduled to Timer or TimerPool by using InstantRunnable. All the elements in the same InstantRunnable must have the same scheduled time.
    • Field Detail

      • actions

        protected Set actions
      • removeElementAfterAction

        protected boolean removeElementAfterAction
      • allowToChange

        protected volatile boolean allowToChange
    • Constructor Detail

      • InstantRunnable

        public InstantRunnable​(boolean removeElementAfterAction)
        Constructor of InstantRunnable.
        Parameters:
        removeElementAfterAction - Whether to remove the elements after running the ScheduleableAction on the objects
    • Method Detail

      • run

        public void run()
        Implements for TaskRunnable. Run the function of ScheduleableAction on all the objects 1 by 1.
      • addElement

        public boolean addElement​(Object obj)
        Adds an element to this InstantRunnable.
        Parameters:
        obj - Element to be added to this InstantRunnable
        Returns:
        a boolean to indicate whether the add success
      • removeElement

        public boolean removeElement​(Object obj)
        Removes an element from this InstantRunnable.
        Parameters:
        obj - Element to be removed from this InstantRunnable
        Returns:
        A boolean to indicate whether the remove success
      • isEmpty

        public boolean isEmpty()
        Indicates whether this InstantRunnable is empty.
        Returns:
        A boolean to indicate whether this InstantRunnable is empty
      • getRunPeriod

        public long getRunPeriod()
        Returns the run period of this InstantRunnable.
        Returns:
        -1 means this task doesn't have a run period
      • reset

        public void reset()
        Resets this InstantRunnable to allow elements to be added.