Package rx.internal.schedulers
Class NewThreadWorker
java.lang.Object
rx.Scheduler.Worker
rx.internal.schedulers.NewThreadWorker
- All Implemented Interfaces:
Subscription
- Direct Known Subclasses:
CachedThreadScheduler.ThreadWorker,EventLoopsScheduler.PoolWorker
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static ObjectImproves performance oftryEnableCancelPolicy(ScheduledExecutorService).private final ScheduledExecutorServiceprivate static final ConcurrentHashMap<ScheduledThreadPoolExecutor, ScheduledThreadPoolExecutor> private static final StringThe purge frequency in milliseconds.(package private) booleanprivate static final AtomicReference<ScheduledExecutorService> private static final StringForce the use of purge (true/false).static final intThe purge frequency in milliseconds.private static final Stringprivate static final ObjectPossible value ofcachedSetRemoveOnCancelPolicyMethodwhich means that cancel policy is not supported.private static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidDeregisters the executor service.(package private) static MethodTries to find"setRemoveOnCancelPolicy(boolean)"method in the class of passed executor.booleanIndicates whether thisSubscriptionis currently unsubscribed.(package private) static voidPurges each registered executor and eagerly evicts shutdown executors.static voidRegisters the given executor service and starts the purge thread if not already started.Schedules an Action for execution.Schedules an Action for execution at some point in the future.scheduleActual(Action0 action, long delayTime, TimeUnit unit) Schedules the given action by wrapping it into a ScheduledAction on the underlying ExecutorService, returning the ScheduledAction.scheduleActual(Action0 action, long delayTime, TimeUnit unit, SubscriptionList parent) scheduleActual(Action0 action, long delayTime, TimeUnit unit, CompositeSubscription parent) static booleanTries to enable the Java 7+ setRemoveOnCancelPolicy.voidStops the receipt of notifications on theSubscriberthat was registered when this Subscription was received.Methods inherited from class rx.Scheduler.Worker
now, schedulePeriodically
-
Field Details
-
executor
-
isUnsubscribed
volatile boolean isUnsubscribed -
FREQUENCY_KEY
The purge frequency in milliseconds.- See Also:
-
PURGE_FORCE_KEY
Force the use of purge (true/false).- See Also:
-
PURGE_THREAD_PREFIX
- See Also:
-
SHOULD_TRY_ENABLE_CANCEL_POLICY
private static final boolean SHOULD_TRY_ENABLE_CANCEL_POLICY -
PURGE_FREQUENCY
public static final int PURGE_FREQUENCYThe purge frequency in milliseconds. -
EXECUTORS
private static final ConcurrentHashMap<ScheduledThreadPoolExecutor,ScheduledThreadPoolExecutor> EXECUTORS -
PURGE
-
cachedSetRemoveOnCancelPolicyMethod
Improves performance oftryEnableCancelPolicy(ScheduledExecutorService). Also, it works even for inheritance:Methodof base class can be invoked on the instance of child class. -
SET_REMOVE_ON_CANCEL_POLICY_METHOD_NOT_SUPPORTED
Possible value ofcachedSetRemoveOnCancelPolicyMethodwhich means that cancel policy is not supported.
-
-
Constructor Details
-
NewThreadWorker
-
-
Method Details
-
registerExecutor
Registers the given executor service and starts the purge thread if not already started.publicvisibility reason: called from other package(s) within RxJava- Parameters:
service- a scheduled thread pool executor instance
-
deregisterExecutor
Deregisters the executor service.publicvisibility reason: called from other package(s) within RxJava- Parameters:
service- a scheduled thread pool executor instance
-
purgeExecutors
Purges each registered executor and eagerly evicts shutdown executors. -
tryEnableCancelPolicy
Tries to enable the Java 7+ setRemoveOnCancelPolicy.publicvisibility reason: called from other package(s) within RxJava. If the method returns false, theregisterExecutor(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
Tries to find"setRemoveOnCancelPolicy(boolean)"method in the class of passed executor. -
schedule
Description copied from class:Scheduler.WorkerSchedules an Action for execution.- Specified by:
schedulein classScheduler.Worker- Parameters:
action- Action to schedule- Returns:
- a subscription to be able to unsubscribe the action (unschedule it if not executed)
-
schedule
Description copied from class:Scheduler.WorkerSchedules an Action for execution at some point in the future.Note to implementors: non-positive
delayTimeshould be regarded as undelayed schedule, i.e., as if theScheduler.Worker.schedule(rx.functions.Action0)was called.- Specified by:
schedulein classScheduler.Worker- Parameters:
action- the Action to scheduledelayTime- time to wait before executing the action; non-positive values indicate an undelayed scheduleunit- the time unit ofdelayTime- Returns:
- a subscription to be able to unsubscribe the action (unschedule it if not executed)
-
scheduleActual
Schedules the given action by wrapping it into a ScheduledAction on the underlying ExecutorService, returning the ScheduledAction.- Parameters:
action- the action to wrap and scheduledelayTime- the delay in executionunit- 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:SubscriptionStops the receipt of notifications on theSubscriberthat was registered when this Subscription was received.This allows unregistering an
Subscriberbefore it has finished receiving all events (i.e. before onCompleted is called).- Specified by:
unsubscribein interfaceSubscription
-
isUnsubscribed
public boolean isUnsubscribed()Description copied from interface:SubscriptionIndicates whether thisSubscriptionis currently unsubscribed.- Specified by:
isUnsubscribedin interfaceSubscription- Returns:
trueif thisSubscriptionis currently unsubscribed,falseotherwise
-