public final class Scheduler extends Object
Scheduler instance reference a group of jobs
and is responsible to schedule these jobs at the expected time.| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_MINIMUM_DELAY_IN_MILLIS_TO_REPLACE_JOB
Deprecated.
This value is not used anymore
It will be deleted in version 3.0.0.
|
static int |
DEFAULT_THREAD_POOL_SIZE
Deprecated.
Default values are available in
SchedulerConfig
It will be deleted in version 3.0.0. |
| Constructor and Description |
|---|
Scheduler()
Create a scheduler with the defaults defined at
SchedulerConfig |
Scheduler(int maxThreads)
Create a scheduler with the defaults defined at
SchedulerConfig
and with a max number of worker threads |
Scheduler(int maxThreads,
long minimumDelayInMillisToReplaceJob)
Deprecated.
Use
Scheduler(SchedulerConfig) to specify multiple configuration values.
It will be deleted in version 3.0.0. |
Scheduler(int maxThreads,
long minimumDelayInMillisToReplaceJob,
TimeProvider timeProvider)
Deprecated.
Use
Scheduler(SchedulerConfig) to specify multiple configuration values.
It will be deleted in version 3.0.0. |
Scheduler(SchedulerConfig config)
Create a scheduler according to the configuration
|
| Modifier and Type | Method and Description |
|---|---|
CompletionStage<Job> |
cancel(String jobName)
Issue a cancellation order for a job and
returns immediately a promise that enables to follow the job cancellation status
If the job is running, the scheduler will wait until it is finished to remove it from the jobs pool. |
Optional<Job> |
findJob(String name)
Find a job by its name
|
void |
gracefullyShutdown()
Wait until the current running jobs are executed
and cancel jobs that are planned to be executed.
|
void |
gracefullyShutdown(Duration timeout)
Wait until the current running jobs are executed
and cancel jobs that are planned to be executed.
|
Collection<Job> |
jobStatus()
Fetch the status of all the jobs that has been registered on the
Scheduler
including the JobStatus.DONE jobs |
void |
remove(String jobName)
Remove a terminated job, so with the status
JobStatus.DONE),
from the monitored jobs. |
Job |
schedule(Runnable runnable,
Schedule when)
Schedule the executions of a process.
|
Job |
schedule(String nullableName,
Runnable runnable,
Schedule when)
Schedule the executions of a process.
|
SchedulerStats |
stats()
Fetch statistics about the current
Scheduler |
@Deprecated public static final int DEFAULT_THREAD_POOL_SIZE
SchedulerConfig
It will be deleted in version 3.0.0.@Deprecated public static final long DEFAULT_MINIMUM_DELAY_IN_MILLIS_TO_REPLACE_JOB
public Scheduler()
SchedulerConfigpublic Scheduler(int maxThreads)
SchedulerConfig
and with a max number of worker threadsmaxThreads - The maximum number of worker threads that can be created for the scheduler.IllegalArgumentException - if maxThreads <= 0public Scheduler(SchedulerConfig config)
IllegalArgumentException - if one of the following holds:SchedulerConfig#getMinThreads() < 0SchedulerConfig#getThreadsKeepAliveTime() < 0SchedulerConfig#getMaxThreads() <= 0SchedulerConfig#getMaxThreads() < SchedulerConfig#getMinThreads()NullPointerException - if SchedulerConfig#getTimeProvider() is null@Deprecated public Scheduler(int maxThreads, long minimumDelayInMillisToReplaceJob)
Scheduler(SchedulerConfig) to specify multiple configuration values.
It will be deleted in version 3.0.0.IllegalArgumentException - if maxThreads <= 0@Deprecated public Scheduler(int maxThreads, long minimumDelayInMillisToReplaceJob, TimeProvider timeProvider)
Scheduler(SchedulerConfig) to specify multiple configuration values.
It will be deleted in version 3.0.0.IllegalArgumentException - if maxThreads <= 0NullPointerException - if timeProvider is nullpublic Job schedule(Runnable runnable, Schedule when)
runnable - The process to be executed at a schedulewhen - The Schedule at which the process will be executedJob created.NullPointerException - if runnable or when are nullIllegalArgumentException - if the same instance of runnable is
scheduled twice whereas the corresponding job status is not JobStatus.DONEpublic Job schedule(String nullableName, Runnable runnable, Schedule when)
JobStatus.DONE,
then the created job will inherit the stats of the existing done job:
Job.executionsCount() and Job.lastExecutionTimeInMillis()nullableName - The name of the created jobrunnable - The process to be executed at a schedulewhen - The Schedule at which the process will be executedJob created.NullPointerException - if runnable or when are nullIllegalArgumentException - if the same nullableName is
scheduled twice whereas the corresponding job status is not JobStatus.DONEpublic Collection<Job> jobStatus()
Scheduler
including the JobStatus.DONE jobspublic CompletionStage<Job> cancel(String jobName)
JobStatus.DONE.jobName - The job name to cancelcancel(String)
is called, the promise will succeed when the job has finished executing.IllegalArgumentException - if there is no job corresponding to the job name.public void remove(String jobName)
JobStatus.DONE),
from the monitored jobs. The monitored jobs are the ones
still referenced using jobStatus().
This can be useful to avoid memory leak in case many jobs
with a short lifespan are created.jobName - The job name to removeIllegalArgumentException - If there is no job corresponding to the job name or if the job is not on the status JobStatus.DONE)public void gracefullyShutdown()
InterruptedException - if the shutdown lasts more than 10 secondspublic void gracefullyShutdown(Duration timeout)
timeout - The maximum time to waitInterruptedException - if the shutdown lasts more than 10 secondspublic SchedulerStats stats()
SchedulerCopyright © 2023 Coreoz. All rights reserved.