DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Clustered Quartz Scheduler With Spring Boot and MongoDB
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Beating the 100-Scheduled-Job Limit in Salesforce
  • Using Event-Driven Ansible to Monitor Your Web Application

Trending

  • Useful System Table Queries in Relational Databases
  • Bridging UI, DevOps, and AI: A Full-Stack Engineer’s Approach to Resilient Systems
  • Is Big Data Dying?
  • Apache Spark 4.0: Transforming Big Data Analytics to the Next Level
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Maintenance
  4. Quartz Scheduler Configuration For Web Applications

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.

By 
Siva Prasad Rao Janapati user avatar
Siva Prasad Rao Janapati
·
Apr. 25, 16 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
24.9K Views

Join the DZone community and get the full member experience.

Join For Free

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);

 @Override
 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"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
 version="1.8">

<schedule>
 <job>
 <name>mailSenderJob</name>
 <group>MYJOB_GROUP</group>
 <description>This job will trigger mail service for every minute</description>
 <job-class>com.smarttechies.job.MailSenderJob</job-class>
 </job>

<trigger>
 <cron>
 <name>mailSenderTrigger</name>
 <group>MYTRIGGER_GROUP</group>
 <job-name>mailSenderJob</job-name>
 <job-group>MYJOB_GROUP</job-group>
 <!-- trigger every -->
 <cron-expression>0 0/1 * 1/1 * ? *</cron-expression>
 </cron>
</trigger>
</schedule>
</job-scheduling-data>

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.

<listener>
 <listener-class>
 org.quartz.ee.servlet.QuartzInitializerListener
 </listener-class>
</listener>

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.
 NOT STARTED.
 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.

Web application Quartz (scheduler) job scheduling

Published at DZone with permission of Siva Prasad Rao Janapati, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Clustered Quartz Scheduler With Spring Boot and MongoDB
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Beating the 100-Scheduled-Job Limit in Salesforce
  • Using Event-Driven Ansible to Monitor Your Web Application

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!