Class NewThreadWorker

java.lang.Object
rx.Scheduler.Worker
rx.internal.schedulers.NewThreadWorker
All Implemented Interfaces:
Subscription
Direct Known Subclasses:
CachedThreadScheduler.ThreadWorker, EventLoopsScheduler.PoolWorker

public class NewThreadWorker extends Scheduler.Worker implements Subscription
  • Field Details

  • Constructor Details

    • NewThreadWorker

      public NewThreadWorker(ThreadFactory threadFactory)
  • Method Details

    • registerExecutor

      public static void registerExecutor(ScheduledThreadPoolExecutor service)
      Registers the given executor service and starts the purge thread if not already started.

      public visibility reason: called from other package(s) within RxJava

      Parameters:
      service - a scheduled thread pool executor instance
    • deregisterExecutor

      public static void deregisterExecutor(ScheduledExecutorService service)
      Deregisters the executor service.

      public visibility reason: called from other package(s) within RxJava

      Parameters:
      service - a scheduled thread pool executor instance
    • purgeExecutors

      @SuppressAnimalSniffer static void purgeExecutors()
      Purges each registered executor and eagerly evicts shutdown executors.
    • tryEnableCancelPolicy

      public static boolean tryEnableCancelPolicy(ScheduledExecutorService executor)
      Tries to enable the Java 7+ setRemoveOnCancelPolicy.

      public visibility reason: called from other package(s) within RxJava. If the method returns false, the registerExecutor(ScheduledThreadPoolExecutor) may be called to enable the backup option of purging the executors.

      Parameters:
      executor - the executor to call setRemoveOnCaneclPolicy if available.
      Returns:
      true if the policy was successfully enabled
    • findSetRemoveOnCancelPolicyMethod

      static Method findSetRemoveOnCancelPolicyMethod(ScheduledExecutorService executor)
      Tries to find "setRemoveOnCancelPolicy(boolean)" method in the class of passed executor.
      Parameters:
      executor - whose class will be used to search for required method.
      Returns:
      "setRemoveOnCancelPolicy(boolean)" Method or null if required Method was not found.
    • schedule

      public Subscription schedule(Action0 action)
      Description copied from class: Scheduler.Worker
      Schedules an Action for execution.
      Specified by:
      schedule in class Scheduler.Worker
      Parameters:
      action - Action to schedule
      Returns:
      a subscription to be able to unsubscribe the action (unschedule it if not executed)
    • schedule

      public Subscription schedule(Action0 action, long delayTime, TimeUnit unit)
      Description copied from class: Scheduler.Worker
      Schedules an Action for execution at some point in the future.

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

      Specified by:
      schedule in class Scheduler.Worker
      Parameters:
      action - the Action to schedule
      delayTime - time to wait before executing the action; non-positive values indicate an undelayed schedule
      unit - the time unit of delayTime
      Returns:
      a subscription to be able to unsubscribe the action (unschedule it if not executed)
    • scheduleActual

      public ScheduledAction scheduleActual(Action0 action, long delayTime, TimeUnit unit)
      Schedules the given action by wrapping it into a ScheduledAction on the underlying ExecutorService, returning the ScheduledAction.
      Parameters:
      action - the action to wrap and schedule
      delayTime - the delay in execution
      unit - the time unit of the delay
      Returns:
      the wrapper ScheduledAction
    • scheduleActual

      public ScheduledAction scheduleActual(Action0 action, long delayTime, TimeUnit unit, CompositeSubscription parent)
    • scheduleActual

      public ScheduledAction scheduleActual(Action0 action, long delayTime, TimeUnit unit, SubscriptionList parent)
    • unsubscribe

      public void unsubscribe()
      Description copied from interface: Subscription
      Stops the receipt of notifications on the Subscriber that was registered when this Subscription was received.

      This allows unregistering an Subscriber before it has finished receiving all events (i.e. before onCompleted is called).

      Specified by:
      unsubscribe in interface Subscription
    • isUnsubscribed

      public boolean isUnsubscribed()
      Description copied from interface: Subscription
      Indicates whether this Subscription is currently unsubscribed.
      Specified by:
      isUnsubscribed in interface Subscription
      Returns:
      true if this Subscription is currently unsubscribed, false otherwise