@InterfaceAudience.Public public class ChoreService extends Object
ScheduledChore
to run
periodically while sharing threads. The ChoreService is backed by a
ScheduledThreadPoolExecutor
whose core pool size changes dynamically depending on the
number of ScheduledChore
scheduled. All of the threads in the core thread pool of the
underlying ScheduledThreadPoolExecutor
are set to be daemon threads.
The ChoreService provides the ability to schedule, cancel, and trigger instances of
ScheduledChore
. The ChoreService also provides the ability to check on the status of
scheduled chores. The number of threads used by the ChoreService changes based on the scheduling
load and whether or not the scheduled chores are executing on time. As more chores are scheduled,
there may be a need to increase the number of threads if it is noticed that chores are no longer
meeting their scheduled start times. On the other hand, as chores are cancelled, an attempt is
made to reduce the number of running threads to see if chores can still meet their start times
with a smaller thread pool.
When finished with a ChoreService it is good practice to call shutdown()
.
Calling this method ensures that all scheduled chores are cancelled and cleaned up properly.
Constructor and Description |
---|
ChoreService(String coreThreadPoolPrefix) |
ChoreService(String coreThreadPoolPrefix,
boolean jitter) |
ChoreService(String coreThreadPoolPrefix,
int corePoolSize,
boolean jitter) |
Modifier and Type | Method and Description |
---|---|
boolean |
isShutdown() |
boolean |
isTerminated() |
boolean |
scheduleChore(ScheduledChore chore) |
void |
shutdown()
shutdown the service.
|
@InterfaceAudience.Private public ChoreService(String coreThreadPoolPrefix)
coreThreadPoolPrefix
- Prefix that will be applied to the Thread name of all threads
spawned by this servicepublic ChoreService(String coreThreadPoolPrefix, boolean jitter)
coreThreadPoolPrefix
- Prefix that will be applied to the Thread name of all threads
spawned by this servicejitter
- Should chore service add some jitter for all of the scheduled chores. When set
to true this will add -10% to 10% jitter.public ChoreService(String coreThreadPoolPrefix, int corePoolSize, boolean jitter)
coreThreadPoolPrefix
- Prefix that will be applied to the Thread name of all threads
spawned by this servicecorePoolSize
- The initial size to set the core pool of the ScheduledThreadPoolExecutor
to during initialization. The default size is 1, but specifying a larger size may be
beneficial if you know that 1 thread will not be enough.jitter
- Should chore service add some jitter for all of the scheduled chores. When set
to true this will add -10% to 10% jitter.public boolean scheduleChore(ScheduledChore chore)
chore
- Chore to be scheduled. If the chore is already scheduled with another ChoreService
instance, that schedule will be cancelled (i.e. a Chore can only ever be scheduled
with a single ChoreService instance).public void shutdown()
public boolean isShutdown()
public boolean isTerminated()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.