Top Description Fields Constructors Methods
org.springframework.scheduling.config

public Class TaskSchedulerRouter

extends Object
implements TaskScheduler, BeanNameAware, BeanFactoryAware, DisposableBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.scheduling.TaskScheduler
Imports
java.time.Duration, .Instant, java.util.concurrent.Executors, .ScheduledExecutorService, .ScheduledFuture, java.util.function.Supplier, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, .BeanNameAware, .BeanNotOfRequiredTypeException, .DisposableBean, .NoSuchBeanDefinitionException, .NoUniqueBeanDefinitionException, org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils, org.springframework.beans.factory.config.AutowireCapableBeanFactory, .ConfigurableBeanFactory, .EmbeddedValueResolver, .NamedBeanHolder, org.springframework.lang.Nullable, org.springframework.scheduling.SchedulingAwareRunnable, .TaskScheduler, .Trigger, org.springframework.scheduling.concurrent.ConcurrentTaskScheduler, org.springframework.util.Assert, .StringUtils, .StringValueResolver, org.springframework.util.function.SingletonSupplier

A routing implementation of the TaskScheduler interface, delegating to a target scheduler based on an identified qualifier or using a default scheduler otherwise.
Author
Juergen Hoeller
Since
6.1
See Also
SchedulingAwareRunnable#getQualifier()

Field Summary

Modifier and TypeField and Description
private BeanFactory
private String
public static final String
DEFAULT_TASK_SCHEDULER_BEAN_NAME

The default name of the TaskScheduler bean to pick up: taskScheduler.

private final Supplier<TaskScheduler>
private StringValueResolver
private volatile ScheduledExecutorService
protected static final Log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Destroy the local default executor, if any.

protected TaskScheduler
protected TaskScheduler
protected String
protected TaskScheduler
private <T> T
resolveSchedulerBean(BeanFactory beanFactory, Class<T> schedulerType, boolean byName)

public ScheduledFuture<?>
schedule(Runnable
the Runnable to execute whenever the trigger fires
task
,
Trigger
an implementation of the Trigger interface, e.g. a org.springframework.scheduling.support.CronTrigger object wrapping a cron expression
trigger
)

Implements org.springframework.scheduling.TaskScheduler.schedule.

Schedule the given Runnable, invoking it whenever the trigger indicates a next execution time.

public ScheduledFuture<?>
schedule(Runnable
the Runnable to execute whenever the trigger fires
task
,
Instant
the desired execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
startTime
)

Implements org.springframework.scheduling.TaskScheduler.schedule.

Schedule the given Runnable, invoking it at the specified execution time.

public ScheduledFuture<?>
scheduleAtFixedRate(Runnable
the Runnable to execute whenever the trigger fires
task
,
Instant
the desired first execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
startTime
,
Duration
the interval between successive executions of the task
period
)

Implements org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate.

Schedule the given Runnable, invoking it at the specified execution time and subsequently with the given period.

public ScheduledFuture<?>
scheduleAtFixedRate(Runnable
the Runnable to execute whenever the trigger fires
task
,
Duration
the interval between successive executions of the task
period
)

Implements org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate.

Schedule the given Runnable, starting as soon as possible and invoking it with the given period.

public ScheduledFuture<?>
scheduleWithFixedDelay(Runnable
the Runnable to execute whenever the trigger fires
task
,
Instant
the desired first execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
startTime
,
Duration
the delay between the completion of one execution and the start of the next
delay
)

Implements org.springframework.scheduling.TaskScheduler.scheduleWithFixedDelay.

Schedule the given Runnable, invoking it at the specified execution time and subsequently with the given delay between the completion of one execution and the start of the next.

public ScheduledFuture<?>
scheduleWithFixedDelay(Runnable
the Runnable to execute whenever the trigger fires
task
,
Duration
the delay between the completion of one execution and the start of the next
delay
)

Implements org.springframework.scheduling.TaskScheduler.scheduleWithFixedDelay.

Schedule the given Runnable, starting as soon as possible and invoking it with the given delay between the completion of one execution and the start of the next.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

The bean factory for scheduler lookups.

public void
setBeanName(String
the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.
name
)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

The bean name for this router, or the bean name of the containing bean if the router instance is internally held.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanFactoryback to summary
private BeanFactory beanFactory
Annotations
@Nullable
beanNameback to summary
private String beanName
Annotations
@Nullable
DEFAULT_TASK_SCHEDULER_BEAN_NAMEback to summary
public static final String DEFAULT_TASK_SCHEDULER_BEAN_NAME

The default name of the TaskScheduler bean to pick up: taskScheduler.

Note that the initial lookup happens by type; this is just the fallback in case of multiple scheduler beans found in the context.

defaultSchedulerback to summary
private final Supplier<TaskScheduler> defaultScheduler
embeddedValueResolverback to summary
private StringValueResolver embeddedValueResolver
Annotations
@Nullable
localExecutorback to summary
private volatile ScheduledExecutorService localExecutor
Annotations
@Nullable
loggerback to summary
protected static final Log logger

Constructor Detail

TaskSchedulerRouterback to summary
public TaskSchedulerRouter()

Method Detail

destroyback to summary
public void destroy()

Implements org.springframework.beans.factory.DisposableBean.destroy.

Destroy the local default executor, if any.

Annotations
@Override
determineDefaultSchedulerback to summary
protected TaskScheduler determineDefaultScheduler()
determineQualifiedSchedulerback to summary
protected TaskScheduler determineQualifiedScheduler(String qualifier)
determineQualifierback to summary
protected String determineQualifier(Runnable task)
Annotations
@Nullable
determineTargetSchedulerback to summary
protected TaskScheduler determineTargetScheduler(Runnable task)
resolveSchedulerBeanback to summary
private <T> T resolveSchedulerBean(BeanFactory beanFactory, Class<T> schedulerType, boolean byName)
scheduleback to summary
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger)

Implements org.springframework.scheduling.TaskScheduler.schedule.

Doc from org.springframework.scheduling.TaskScheduler.schedule.

Schedule the given Runnable, invoking it whenever the trigger indicates a next execution time.

Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.

Parameters
task:Runnable

the Runnable to execute whenever the trigger fires

trigger:Trigger

an implementation of the Trigger interface, e.g. a org.springframework.scheduling.support.CronTrigger object wrapping a cron expression

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task, or null if the given Trigger object never fires (i.e. returns null from Trigger#nextExecution)

Annotations
@Override
scheduleback to summary
public ScheduledFuture<?> schedule(Runnable task, Instant startTime)

Implements org.springframework.scheduling.TaskScheduler.schedule.

Doc from org.springframework.scheduling.TaskScheduler.schedule.

Schedule the given Runnable, invoking it at the specified execution time.

Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.

Parameters
task:Runnable

the Runnable to execute whenever the trigger fires

startTime:Instant

the desired execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task

Annotations
@Override
scheduleAtFixedRateback to summary
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Instant startTime, Duration period)

Implements org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate.

Doc from org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate.

Schedule the given Runnable, invoking it at the specified execution time and subsequently with the given period.

Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.

Parameters
task:Runnable

the Runnable to execute whenever the trigger fires

startTime:Instant

the desired first execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)

period:Duration

the interval between successive executions of the task

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task

Annotations
@Override
scheduleAtFixedRateback to summary
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Duration period)

Implements org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate.

Doc from org.springframework.scheduling.TaskScheduler.scheduleAtFixedRate.

Schedule the given Runnable, starting as soon as possible and invoking it with the given period.

Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.

Parameters
task:Runnable

the Runnable to execute whenever the trigger fires

period:Duration

the interval between successive executions of the task

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task

Annotations
@Override
scheduleWithFixedDelayback to summary
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay)

Implements org.springframework.scheduling.TaskScheduler.scheduleWithFixedDelay.

Doc from org.springframework.scheduling.TaskScheduler.scheduleWithFixedDelay.

Schedule the given Runnable, invoking it at the specified execution time and subsequently with the given delay between the completion of one execution and the start of the next.

Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.

Parameters
task:Runnable

the Runnable to execute whenever the trigger fires

startTime:Instant

the desired first execution time for the task (if this is in the past, the task will be executed immediately, i.e. as soon as possible)

delay:Duration

the delay between the completion of one execution and the start of the next

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task

Annotations
@Override
scheduleWithFixedDelayback to summary
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Duration delay)

Implements org.springframework.scheduling.TaskScheduler.scheduleWithFixedDelay.

Doc from org.springframework.scheduling.TaskScheduler.scheduleWithFixedDelay.

Schedule the given Runnable, starting as soon as possible and invoking it with the given delay between the completion of one execution and the start of the next.

Execution will end once the scheduler shuts down or the returned ScheduledFuture gets cancelled.

Parameters
task:Runnable

the Runnable to execute whenever the trigger fires

delay:Duration

the delay between the completion of one execution and the start of the next

Returns:ScheduledFuture<?>

a ScheduledFuture representing pending completion of the task

Annotations
@Override
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

The bean factory for scheduler lookups.

Parameters
beanFactory:BeanFactory

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override
setBeanNameback to summary
public void setBeanName(String name)

Implements org.springframework.beans.factory.BeanNameAware.setBeanName.

The bean name for this router, or the bean name of the containing bean if the router instance is internally held.

Parameters
name:String

Doc from org.springframework.beans.factory.BeanNameAware.setBeanName.

the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils#originalBeanName(String) method to extract the original bean name (without suffix), if desired.

Annotations
@Override