Class NewThreadWorker

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) boolean disposed  
      private java.util.concurrent.ScheduledExecutorService executor  
    • Constructor Summary

      Constructors 
      Constructor Description
      NewThreadWorker​(java.util.concurrent.ThreadFactory threadFactory)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()
      Dispose the resource, the operation should be idempotent.
      boolean isDisposed()
      Returns true if this resource has been disposed.
      @NonNull Disposable schedule​(@NonNull java.lang.Runnable run)
      Schedules a Runnable for execution without any time delay.
      @NonNull Disposable schedule​(@NonNull java.lang.Runnable action, long delayTime, @NonNull java.util.concurrent.TimeUnit unit)
      Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.
      @NonNull ScheduledRunnable scheduleActual​(java.lang.Runnable run, long delayTime, @NonNull java.util.concurrent.TimeUnit unit, @Nullable DisposableContainer parent)
      Wraps and returns the given runnable into a ScheduledRunnable and schedules it on the underlying ScheduledExecutorService.
      Disposable scheduleDirect​(java.lang.Runnable run, long delayTime, java.util.concurrent.TimeUnit unit)
      Schedules the given runnable on the underlying executor directly and returns its future wrapped into a Disposable.
      Disposable schedulePeriodicallyDirect​(java.lang.Runnable run, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
      Schedules the given runnable periodically on the underlying executor directly and returns its future wrapped into a Disposable.
      void shutdown()
      Shuts down the underlying executor in a non-interrupting fashion.
      • Methods inherited from class java.lang.Object

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

      • executor

        private final java.util.concurrent.ScheduledExecutorService executor
      • disposed

        volatile boolean disposed
    • Constructor Detail

      • NewThreadWorker

        public NewThreadWorker​(java.util.concurrent.ThreadFactory threadFactory)
    • Method Detail

      • schedule

        @NonNull
        public @NonNull Disposable schedule​(@NonNull
                                            @NonNull java.lang.Runnable action,
                                            long delayTime,
                                            @NonNull
                                            @NonNull java.util.concurrent.TimeUnit unit)
        Description copied from class: Scheduler.Worker
        Schedules an Runnable for execution at some point in the future specified by a time delay relative to the current time.

        Note to implementors: non-positive delayTime should be regarded as non-delayed schedule, i.e., as if the Scheduler.Worker.schedule(Runnable) was called.

        Specified by:
        schedule in class Scheduler.Worker
        Parameters:
        action - the Runnable to schedule
        delayTime - time to "wait" before executing the action; non-positive values indicate an non-delayed schedule
        unit - the time unit of delayTime
        Returns:
        a Disposable to be able to unsubscribe the action (cancel it if not executed)
      • scheduleDirect

        public Disposable scheduleDirect​(java.lang.Runnable run,
                                         long delayTime,
                                         java.util.concurrent.TimeUnit unit)
        Schedules the given runnable on the underlying executor directly and returns its future wrapped into a Disposable.
        Parameters:
        run - the Runnable to execute in a delayed fashion
        delayTime - the delay amount
        unit - the delay time unit
        Returns:
        the ScheduledRunnable instance
      • schedulePeriodicallyDirect

        public Disposable schedulePeriodicallyDirect​(java.lang.Runnable run,
                                                     long initialDelay,
                                                     long period,
                                                     java.util.concurrent.TimeUnit unit)
        Schedules the given runnable periodically on the underlying executor directly and returns its future wrapped into a Disposable.
        Parameters:
        run - the Runnable to execute in a periodic fashion
        initialDelay - the initial delay amount
        period - the repeat period amount
        unit - the time unit for both the initialDelay and period
        Returns:
        the ScheduledRunnable instance
      • scheduleActual

        @NonNull
        public @NonNull ScheduledRunnable scheduleActual​(java.lang.Runnable run,
                                                         long delayTime,
                                                         @NonNull
                                                         @NonNull java.util.concurrent.TimeUnit unit,
                                                         @Nullable
                                                         @Nullable DisposableContainer parent)
        Wraps and returns the given runnable into a ScheduledRunnable and schedules it on the underlying ScheduledExecutorService.
        Parameters:
        run - the runnable instance
        delayTime - the time to delay the execution
        unit - the time unit
        parent - the optional tracker parent to add the created ScheduledRunnable instance to before it gets scheduled
        Returns:
        the ScheduledRunnable instance
      • dispose

        public void dispose()
        Description copied from interface: Disposable
        Dispose the resource, the operation should be idempotent.
      • shutdown

        public void shutdown()
        Shuts down the underlying executor in a non-interrupting fashion.
      • isDisposed

        public boolean isDisposed()
        Description copied from interface: Disposable
        Returns true if this resource has been disposed.
        Returns:
        true if this resource has been disposed