How to create multiple instances of a scheduler class in spring boot?

spring scheduler multiple instances
spring cloud scheduler
spring boot scheduler example mkyong
spring scheduler run once
spring task scheduler
spring scheduler cron expression from database
spring boot scheduled(cron every 5 minutes)
spring integration task scheduler

I have a class containing the @Scheduled annotated method. I want to create multiple instances of a class in spring boot application so that I should be able to run multiple jobs for the specified time period.

I have googled and tried with creating a new object but scheduling didn't work.

Note: I will pass what to execute at runtime for respective instance.

You can create a class with multiple methods to schedule your jobs at same time, doing same job..

public class Job {

    @Scheduled(initialDelay = 1000, fixedDelay = 60000)
    public void job1() {

    @Scheduled(initialDelay = 1000, fixedDelay = 60000)
    public void job2() {

    private void jobWork() {


Dynamically Schedule the Same Task with Multiple Cron Expression , We have seen how to schedule a task within Spring or Spring Boot Creating a cron trigger task with Spring is pretty easy by adding a SchedulingConfigurer class has one method, configureTasks(ScheduledTaskRegistrar  We have seen how to schedule a task within Spring or Spring Boot using a cron expression, with fixed delays. In this in this tutorial, we will see how to schedule a task with multiple cron

@Scheduled is a repatable annotation so you can add multiple @Scheduled in same method:

@Scheduled(initialDelay = 1000, fixedDelay = 60000)   
@Scheduled(initialDelay = 1000, fixedDelay = 60000)
public void jobWork() {


See also Duplication on @Scheduled

Repeating Annotations as @Scheduled allow multiple annotations

Guide to ShedLock with Spring, Spring provides an easy to implement API for scheduling jobs. It works great until we deploy multiple instances of our application. Spring Next, we need to create a database table for ShedLock to keep We should declare the data source in our Spring Boot application's class BaeldungTaskScheduler {. So, as a result, TestWire class will isntantiate only when project builds and neither @Scope(value = "prototype"), nor proxyMode = ScopedProxyMode.TARGET_CLASS wont help. Any ideas how to create new instances at runtime? I mean, how can we do it in "Spring way"? Without factories and other things, only Spring DI through annotation and

Here is the answer, I implemented ApplicationContextAware

public void setApplicationContext(ApplicationContext applicationContext)
        throws BeansException {
    for (int i =0;i<4;i++) {
    ((ConfigurableApplicationContext) applicationContext).getBeanFactory()
        .registerSingleton("New Instance " + i, new SchedularJob());

It will create 4 instances of SchedularJob class and 4 schedulers will run independently.

27. Task Execution and Scheduling, Make sure that you are not initializing multiple instances of the same @​Scheduled annotation class at runtime, unless you do want to schedule callbacks to each  To schedule job in spring boot application to run periodically, spring boot provides @EnableScheduling and @Scheduled annotations. Lets learn to use Spring boot @Scheduled annotation. Let’s say you want to run job at every 10 seconds interval. You can achieve this job scheduling in below steps:

Getting Started, This guide walks you through the steps for scheduling tasks with Spring. What You Will Build. You will build an application that prints out the current time every five seconds by using xmlns:xsi="​instance" getLogger(ScheduledTasks.class); private static final SimpleDateFormat  Working With the Java Scheduler The class needs to implement the SchedulingConfigurer interface. How to Schedule a Task Using the Cron Expression in Spring Boot [Video] DZone Article.

spring batch : Running/stopping multiple instances of job, i m a newbie with spring batch. i must develop a job that read from database and write on flat spring boot batch to spring cloud task with multiple jobs I know that I have to define in the main class the #enableTask and also in the I am thinking using spring batch scheduler as it is simple and not with Quartz scheduler. To create a data source bean we need to instantiate the org.springframework.boot.autoconfigure.jdbc.DataSourceProperties class using the data source key specified in the file. We are going to use this DataSourceProperties object to get a data source builder object.

Multiple Executor instances when using @EnableScheduling · Issue , The first creates ThreadPoolTaskExecutor while the second creates '​taskScheduler' in class path resource [org/springframework/boot/  Spring provides excellent support for both task scheduling and asynchronous method execution based on cron expression using @Scheduled annotation. The @Scheduled annotation can be added to a method along with trigger metadata. In this post, I will show the means to use @Scheduled feature in 4 different ways. Read More : Spring timer tasks Table […]