Class ConfigurationScheduler
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.config.ConfigurationScheduler
-
- All Implemented Interfaces:
LifeCycle
,LifeCycle2
public class ConfigurationScheduler extends AbstractLifeCycle
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ConfigurationScheduler.CronRunnable
-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT
-
-
Constructor Summary
Constructors Constructor Description ConfigurationScheduler()
ConfigurationScheduler(String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
decrementScheduledItems()
Decrement the number of threads in the poolvoid
incrementScheduledItems()
Increment the number of threads in the pool.boolean
isExecutorServiceSet()
long
nextFireInterval(Date fireDate)
ScheduledFuture<?>
schedule(Runnable command, long delay, TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.<V> ScheduledFuture<V>
schedule(Callable<V> callable, long delay, TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.ScheduledFuture<?>
scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.CronScheduledFuture<?>
scheduleWithCron(CronExpression cronExpression, Runnable command)
Creates and executes an action that first based on a cron expression.CronScheduledFuture<?>
scheduleWithCron(CronExpression cronExpression, Date startDate, Runnable command)
Creates and executes an action that first based on a cron expression.ScheduledFuture<?>
scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.void
start()
boolean
stop(long timeout, TimeUnit timeUnit)
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.String
toString()
-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
-
-
-
Constructor Detail
-
ConfigurationScheduler
public ConfigurationScheduler()
-
ConfigurationScheduler
public ConfigurationScheduler(String name)
-
-
Method Detail
-
start
public void start()
- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractLifeCycle
-
stop
public boolean stop(long timeout, TimeUnit timeUnit)
Description copied from interface:LifeCycle2
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractLifeCycle
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
isExecutorServiceSet
public boolean isExecutorServiceSet()
-
incrementScheduledItems
public void incrementScheduledItems()
Increment the number of threads in the pool.
-
decrementScheduledItems
public void decrementScheduledItems()
Decrement the number of threads in the pool
-
schedule
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.- Type Parameters:
V
- The result type returned by this Future- Parameters:
callable
- the function to execute.delay
- the time from now to delay execution.unit
- the time unit of the delay parameter.- Returns:
- a ScheduledFuture that can be used to extract result or cancel.
-
schedule
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.- Parameters:
command
- the task to execute.delay
- the time from now to delay execution.unit
- the time unit of the delay parameter.- Returns:
- a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion.
-
scheduleWithCron
public CronScheduledFuture<?> scheduleWithCron(CronExpression cronExpression, Runnable command)
Creates and executes an action that first based on a cron expression.- Parameters:
cronExpression
- the cron expression describing the schedule.command
- The Runnable to run,- Returns:
- a ScheduledFuture representing the next time the command will run.
-
scheduleWithCron
public CronScheduledFuture<?> scheduleWithCron(CronExpression cronExpression, Date startDate, Runnable command)
Creates and executes an action that first based on a cron expression.- Parameters:
cronExpression
- the cron expression describing the schedule.startDate
- The time to use as the time to begin the cron expression. Defaults to the current date and time.command
- The Runnable to run,- Returns:
- a ScheduledFuture representing the next time the command will run.
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.- Parameters:
command
- the task to execute.initialDelay
- the time to delay first execution.period
- the period between successive executions.unit
- the time unit of the initialDelay and period parameters.- Returns:
- a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.- Parameters:
command
- the task to execute.initialDelay
- the time to delay first execution.delay
- the delay between the termination of one execution and the commencement of the next.unit
- the time unit of the initialDelay and delay parameters- Returns:
- a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
-
nextFireInterval
public long nextFireInterval(Date fireDate)
-
-