Naman Gala
Naman Gala

Reputation: 4692

Implementing scheduler in spring (defined by user)

I am developing spring mvc application.

I have gone through below links

  1. http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-scheduled
  2. http://www.mkyong.com/spring-batch/spring-batch-and-spring-taskscheduler-example/

These guide for how to schedule.

But I have to give it to the users, to schedule(run on daily/weekly basis etc.) some functionality from GUI.

Can any one please help me how can I achieve this?

Upvotes: 2

Views: 1614

Answers (2)

shintoZ
shintoZ

Reputation: 311

Please check the link. It explains how to schedule tasks by giving crone expressions in a property file.

Other solution is using the quartz library directly. We can schedule or reschedule jobs easily using that. Refer this.

Hope this will help.

Upvotes: 2

StanislavL
StanislavL

Reputation: 57381

Suppose you have several tasks to be scheduled by user.

Define a Enum for the tasks names and a Runner to run task by enum. Define a job to be executed every second (minute, hour). The job just checks whether there is a user's task to be executed.

Now user defines such a task whith following params TaskType (the Enum value) TaskTime (when it should be started e.g. 12:00) TaskPeriod (how often it should be called)

TaskTime and TaskPeriod could be joined e.g. in cron expression.

Then all the task info is stored somewhere (e.g. in DB).

Your permanent Job every second reads from the DB whether there is a task to be executed. It checks task time and task period and compares with current time. If it's time to start it gets enum value and calls Runner's method for the enum.

Upvotes: 2

Related Questions