How to execute cron job in Spring ?

Spring framework has built-in support for scheduled tasks. So can schedule tasks using XML as well as annotation also.

XML

<task:scheduled-tasks>
     <task:scheduled ref="beanName" method="methodName" cron="*/5 * * * * *"/>
</task:scheduled-tasks>

Annotation – An annotation that marks a method to be scheduled. Exactly one of the cron(), fixedDelay(), or fixedRate() attributes must be specified.

Processing of @Scheduled annotations is performed by registering a ScheduledAnnotationBeanPostProcessor. This can be done manually or, more conveniently, through the <task:annotation-driven/> element or @EnableScheduling annotation.

@Scheduled(cron=“0/10 * * * * *”) //execute after every 10 seconds

For more detail, Please watch below video –

Thanks for reading 🙂

Please Subscribe our you tube channel Almighty Java

2 thoughts on “How to execute cron job in Spring ?

  1. Pingback: 15 – How to Execute Cron Job? | Execute Task Automatically | Spring MVC | Cron | Almighty Java | Quantum Code

  2. Pingback: 15 - How to Execute Cron Job? | Execute Task Automatically | Spring MVC | Cron | Almighty Java - How To Solve

Leave a comment