SEARCH BY

All

  • All
  • Java8
  • Spring

How to schedule jobs in spring boot using Quartz Scheduler?

4 comments

Introduction to this tutorial

We are going to learn how to schedule jobs in spring boot application by using one of the popular and open source job scheduler named as Quartz Scheduler. We are going to develop an application to send emails as per scheduled time. For example let us consider an E-commerce app wants to send discounts and offers to the customers email at 7am in the morning every day. To develop this feature in our application we need to add job scheduler to out code, because no human can involve to manually send discounts and offers to customer email.

Example applications using Job Scheduler in realtime

There are lot of examples in realtime using job scheduling process. For example in our regular life we are using gmail as a email system, in gmail we have a facility to compose new mail and selecting scheduled time to send mail to our friend. The following figure shows that gmail allows us to send mail at scheduled time.
Scheduling mail in gmail
Scheduling mail in gmail
Newsletters sending by companies like online shopping sites, software offers etc... These newsletters are scheduled to deliver customers.
Newsletters with Offers
Newsletters with Offers
Whats-app backup is also one of the example for scheduling job
Whats-app chat backup
Whats-app chat backup

Technology stack

To develop this application we are using Spring Boot, Quartz Scheduler(Job scheduler), Spring Mail and MySQl database server. Spring boot is for creating REST API application, Quartz Scheduler for creating schedule jobs, Spring Mail for sending email with message, Database server for storing job details.

Introduction to Quartz Scheduler

Quartz is a richly featured, open source job scheduling library that can be integrated within virtually any Java application - from the smallest stand-alone application to the largest e-commerce system. Quartz can be used to create simple or complex schedules for executing tens, hundreds, or even tens-of-thousands of jobs; jobs whose tasks are defined as standard Java components that may execute virtually anything you may program them to do. The Quartz Scheduler includes many enterprise-class features, such as support for JTA transactions and clustering.

The key interfaces of the Quartz API are

Scheduler - the main API for interacting with the scheduler. Scheduler interface can be used to add, remove, and list Jobs and Triggers, and perform other scheduling-related operations (such as pausing a trigger)
Job - an interface to be implemented by components that you wish to have executed by the scheduler. Job interface has only one method named as execute()
JobDetail - used to define instances of Jobs.
Trigger - a component that defines the schedule upon which a given Job will be executed.
JobBuilder - used to define/build JobDetail instances, which define instances of Jobs.
TriggerBuilder - used to define/build Trigger instances.
jaya
I love software designing, coding, writing and teaching...

Share this article

Related Posts

4 comments

Post a Comment

Place your code in <em> </em> tags to send in comments | Do not add hyper links in commnet

Close

Subscribe our newsletter for the latest articles directly into your email inbox