Evan Root
Evan Root

Reputation: 279

How to make a cron to schedule tasks in Spring MVC

I have a function which runs at every day at 1 am in the morning . It retrieves data from the database that needs to run today and then execute them immediately .

What i want is instead of executing the task immediately it rather schedules the task for running somewhere in future at a time that present he row of that task in the database .

How can this be achieved .

Upvotes: 1

Views: 2293

Answers (2)

Vijendra Kumar Kulhade
Vijendra Kumar Kulhade

Reputation: 2255

You simply put time pattern over you method of you Spring managed bean

@Scheduled(cron="0 */5 * * * ?")

This method will run at every 5 mins.

Though Xml you can do it in this way

<bean id="myJobBean" .../>

<task:scheduled-tasks>
  <task:scheduled ref="myJobBean" method="execute" cron="0/60 * * * * *"/>
</task:scheduled-tasks>

This is run the method execute in every 60 sec. you can google for the time pattern.

Upvotes: 2

Navnath
Navnath

Reputation: 133

you can use quartz scheduler .

here is the link to the tutorial

http://www.quartz-scheduler.org/

Upvotes: 0

Related Questions