1

I want to configure scheduler in my application where I have to set cron expression with database values dynamically. When application starts, a method should fetch the database values in set them in cron expression for a particular job. Please help me with this. I am all new to quartz scheduler, spring scheduler concepts

Jag
  • 17
  • 1
  • 5

2 Answers2

3

You can very well use TaskScheduler class of Spring Scheduling in this case.

Please have a look at the class definition:

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/TaskScheduler.html

scheduler.schedule(runnableTask, new CronTrigger(cron, TimeZone.getTimeZone(timezone)));

You can create a runnable task as follows:

class RunnableTask implements Runnable {
    @Override
    public void run() {
        //
    }
}

While creating a cron trigger, you can load cron expression from database.

shankarsh15
  • 1,947
  • 1
  • 11
  • 16
0

You may want to look at this answer. https://stackoverflow.com/a/4499229/82632

Basically you need to autowire TaskScheduler class then programmatically add jobs with it.

Community
  • 1
  • 1
mndeveci
  • 301
  • 4
  • 15