Over a million developers have joined DZone.

Quartz Scheduler Configuration For Web Applications

DZone's Guide to

Quartz Scheduler Configuration For Web Applications

In this article, we will discuss how to configure "Quartz Scheduler" with a web application. Read on for more info.

Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

In this article, we will discuss how to configure "Quartz Scheduler" with a web application. As a first step create a web application and keep all the Quartz Scheduler dependent jars in classpath. Put the quartz.properties and jobs XML file under classes folder.

Let us create a job like shown below:

package com.smarttechies.job;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class MailSenderJob implements Job{

 Logger log = Logger.getLogger(MailSenderJob.class);

 public void execute(JobExecutionContext pArg0) throws JobExecutionException {
 log.info("The mail sender job triggerd");
 //From here call the mail sender service


The configuration of the above job is defined in the job configuration XML file.

<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
 xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"

 <description>This job will trigger mail service for every minute</description>

 <!-- trigger every -->
 <cron-expression>0 0/1 * 1/1 * ? *</cron-expression>

Now, we need to configure the Quartz listener in the web.xml. The listener creates Quartz scheduler and initializes the job when the application is deployed. The web.xml configuration is given below.


It's time to build and deploy the web application. The log of the web container will depict that the job is initialized and triggered.

15:15:19,671 INFO [STDOUT] 15:15:19,671 INFO [QuartzInitializerListener] Quartz Initializer Servlet loaded, initializing Scheduler...
15:15:19,827 INFO [STDOUT] 15:15:19,827 INFO [StdSchedulerFactory] Using default implementation for ThreadExecutor
15:15:19,905 INFO [STDOUT] 15:15:19,905 INFO [SchedulerSignalerImpl] Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
15:15:19,905 INFO [STDOUT] 15:15:19,905 INFO [QuartzScheduler] Quartz Scheduler v.2.1.7 created.
15:15:19,921 INFO [STDOUT] 15:15:19,921 INFO [XMLSchedulingDataProcessorPlugin] Registering Quartz Job Initialization Plug-in.
15:15:19,921 INFO [STDOUT] 15:15:19,921 INFO [RAMJobStore] RAMJobStore initialized.
15:15:19,921 INFO [STDOUT] 15:15:19,921 INFO [QuartzScheduler] Scheduler meta-data: Quartz Scheduler (v2.1.7) 'MailScheduler' with instanceId 'NON_CLUSTERED'
 Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
 Currently in standby mode.
 Number of jobs executed: 0
 Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 3 threads.
 Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
15:15:19,921 INFO [STDOUT] 15:15:19,921 INFO [StdSchedulerFactory] Quartz scheduler 'MailScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
15:15:19,921 INFO [STDOUT] 15:15:19,921 INFO [StdSchedulerFactory] Quartz scheduler version: 2.1.7
15:15:20,061 INFO [STDOUT] 15:15:20,061 INFO [XMLSchedulingDataProcessor] Parsing XML file: mailsenderjobs.xml with systemId: mailsenderjobs.xml
15:15:20,233 INFO [STDOUT] 15:15:20,233 INFO [XMLSchedulingDataProcessor] Adding 1 jobs, 1 triggers.
15:15:20,233 INFO [STDOUT] 15:15:20,233 INFO [XMLSchedulingDataProcessor] Adding job: MYJOB_GROUP.mailSenderJob
15:15:20,249 INFO [STDOUT] 15:15:20,249 INFO [QuartzScheduler] Scheduler MailScheduler_$_NON_CLUSTERED started.
15:15:20,249 INFO [STDOUT] 15:15:20,249 INFO [QuartzInitializerListener] Scheduler has been started...
15:15:20,249 INFO [STDOUT] 15:15:20,249 INFO [QuartzInitializerListener] Storing the Quartz Scheduler Factory in the servlet context at key: org.quartz.impl.StdSchedulerFactory.KEY
15:15:20,280 INFO [STDOUT] 15:15:20,280 WARN [FileScanJob] File 'mailsenderjobs.xml' does not exist.

The source code used for demonstration in this article is available here.

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

java ,quartz ,job scheduling ,java job scheduling

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}