CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-quartz-scheduler--quartz

Quartz Enterprise Job Scheduler - A richly featured, open source job scheduling library that can be integrated within virtually any Java application

Pending
Overview
Eval results
Files

enterprise-features.mddocs/

Enterprise Features

Enterprise-grade capabilities in Quartz including JTA transaction support, clustering, JMX monitoring and management, servlet integration, and specialized job implementations. These features enable Quartz to integrate seamlessly with enterprise application servers and large-scale distributed systems.

Capabilities

JTA Transaction Support

Integration with Java Transaction API (JTA) for transactional job execution.

/**
 * Annotation to mark jobs that should execute within JTA transactions
 */
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@interface ExecuteInJTATransaction {
}

JTA Components:

/**
 * Job run shell that executes jobs within JTA transactions
 */
class JTAJobRunShell extends JobRunShell {
    JTAJobRunShell(Scheduler scheduler, TriggerFiredBundle firedBundle);
}

/**
 * Factory for creating JTA-aware job run shells
 */
class JTAJobRunShellFactory implements JobRunShellFactory {
    void initialize(Scheduler scheduler) throws SchedulerConfigException;
    JobRunShell createJobRunShell(TriggerFiredBundle bundle) throws SchedulerException;
}

/**
 * Annotation-aware JTA job run shell factory
 */
class JTAAnnotationAwareJobRunShellFactory extends JTAJobRunShellFactory {
    // Automatically detects @ExecuteInJTATransaction annotation
}

/**
 * Utility for JTA UserTransaction operations
 */
class UserTransactionHelper {
    UserTransaction lookupUserTransaction() throws NamingException;
    void returnUserTransaction(UserTransaction userTransaction);
}

Servlet Integration

Integration components for web applications and servlet containers.

/**
 * Servlet for initializing Quartz scheduler in web applications
 */
class QuartzInitializerServlet extends HttpServlet {
    // Init parameters:
    String SERVLET_CONTEXT_FACTORY_KEY = "quartz:servlet-context-factory-key";
    String SHUTDOWN_ON_UNLOAD = "shutdown-on-unload";
    String START_SCHEDULER_ON_LOAD = "start-scheduler-on-load";
    String WAIT_ON_SHUTDOWN = "wait-on-shutdown";
    
    void init(ServletConfig cfg) throws ServletException;
    void destroy();
}

/**
 * Context listener for initializing Quartz in web applications
 */
class QuartzInitializerListener implements ServletContextListener {
    String QUARTZ_FACTORY_KEY = "org.quartz.impl.StdSchedulerFactory.KEY";
    
    void contextInitialized(ServletContextEvent sce);
    void contextDestroyed(ServletContextEvent sce);
}

JMX Monitoring and Management

JMX (Java Management Extensions) support for monitoring and managing Quartz schedulers.

/**
 * Management server interface for scheduler monitoring
 */
interface ManagementServer {
    void start() throws Exception;
    void stop() throws Exception;
    boolean isStarted();
    int getPort();
    String getAddress();
}

/**
 * Configuration for REST-based management services
 */
class ManagementRESTServiceConfiguration {
    String getBind();
    void setBind(String bind);
    
    boolean isEnabled();
    void setEnabled(boolean enabled);
    
    String getSecurityServiceLocation();
    void setSecurityServiceLocation(String securityServiceLocation);
    
    String getSslBind();
    void setSslBind(String sslBind);
    
    boolean isNeedClientAuth();
    void setNeedClientAuth(boolean needClientAuth);
}

Clustering Support

Multi-node scheduler clustering with database coordination for high availability and load distribution.

Configuration Properties:

/**
 * Key clustering configuration properties for quartz.properties
 */
interface ClusteringProperties {
    // Enable clustering
    String PROP_CLUSTERED = "org.quartz.jobStore.isClustered";
    
    // Cluster check-in interval (milliseconds)
    String PROP_CLUSTER_CHECKIN_INTERVAL = "org.quartz.jobStore.clusterCheckinInterval";
    
    // Maximum time before instance is considered failed
    String PROP_CLUSTER_CHECKIN_INTERVAL_RECOVERY = "org.quartz.jobStore.clusterCheckinIntervalRecovery";
    
    // Unique instance ID within cluster
    String PROP_INSTANCE_ID = "org.quartz.scheduler.instanceId";
    
    // Instance name (same across cluster)
    String PROP_INSTANCE_NAME = "org.quartz.scheduler.instanceName";
    
    // Auto-generate instance ID
    String PROP_INSTANCE_ID_GENERATOR_CLASS = "org.quartz.scheduler.instanceIdGenerator.class";
}

Clustering Requirements:

  • Database-backed JobStore (JDBC)
  • Synchronized system clocks across nodes
  • Unique instance IDs per node
  • Same quartz.properties across cluster

Specialized Job Implementations

Pre-built job classes for common enterprise tasks from the quartz-jobs module.

/**
 * Base class for jobs that invoke methods on stateless session beans
 */
abstract class EJBInvokerJob implements Job {
    String EJB_JNDI_NAME_KEY = "ejb";
    String EJB_METHOD_KEY = "method";
    String EJB_ARGS_KEY = "args";
    String EJB_ARG_TYPES_KEY = "argTypes";
    
    void execute(JobExecutionContext context) throws JobExecutionException;
}

/**
 * Job for invoking EJB 3.0 stateless session beans
 */
class EJB3InvokerJob extends EJBInvokerJob {
    // Supports EJB 3.0 annotations and dependency injection
}

/**
 * Job for sending JMS queue messages
 */
class SendQueueMessageJob implements Job {
    String JMS_CONNECTION_FACTORY_JNDI = "connection_factory";
    String JMS_DESTINATION_JNDI = "destination";
    String JMS_USE_TXN = "use_txn";
    String JMS_ACK_MODE = "ack_mode";
    String JMS_MSG_FACTORY_CLASS_NAME = "msg_factory_class_name";
    
    void execute(JobExecutionContext context) throws JobExecutionException;
}

/**
 * Job for sending JMS topic messages
 */
class SendTopicMessageJob extends SendQueueMessageJob {
    // Inherits queue functionality, targets topics
}

/**
 * Job for sending email messages
 */
class SendMailJob implements Job {
    String PROP_SMTP_HOST = "smtp_host";
    String PROP_RECIPIENT = "recipient";
    String PROP_SENDER = "sender";
    String PROP_SUBJECT = "subject";
    String PROP_MESSAGE = "message";
    String PROP_CHARSET = "charset";
    
    void execute(JobExecutionContext context) throws JobExecutionException;
}

/**
 * Job for invoking operations on JMX MBeans
 */
class JMXInvokerJob implements Job {
    String JMX_OBJECTNAME = "jmx_objectname";
    String JMX_METHOD = "jmx_method";
    String JMX_METHOD_PARAMS = "jmx_method_params";
    String JMX_METHOD_TYPES = "jmx_method_types";
    
    void execute(JobExecutionContext context) throws JobExecutionException;
}

/**
 * Job for monitoring file system changes
 */
class FileScanJob implements Job {
    String FILE_NAME = "FILE_NAME";
    String FILE_SCAN_LISTENER_NAME = "FILE_SCAN_LISTENER_NAME";
    String MINIMUM_UPDATE_AGE = "MINIMUM_UPDATE_AGE";
    
    void execute(JobExecutionContext context) throws JobExecutionException;
}

/**
 * Job for monitoring directory changes
 */
class DirectoryScanJob extends FileScanJob {
    // Monitors entire directories for changes
}

/**
 * No-operation job for testing and placeholder purposes
 */
class NoOpJob implements Job {
    void execute(JobExecutionContext context) throws JobExecutionException {
        // Intentionally does nothing
    }
}

Plugin System

Extensible plugin architecture for adding custom functionality to schedulers.

/**
 * Interface for scheduler plugins
 */
interface SchedulerPlugin {
    /**
     * Initialize the plugin
     * @param name the plugin name
     * @param scheduler the scheduler instance
     * @throws SchedulerConfigException if initialization fails
     */
    void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;
    
    /**
     * Start the plugin
     */
    void start();
    
    /**
     * Shutdown the plugin
     */
    void shutdown();
}

/**
 * Plugin for loading job and trigger definitions from XML
 */
class XMLSchedulingDataProcessorPlugin implements SchedulerPlugin {
    String PROP_FILE_NAMES = "fileNames";
    String PROP_FAIL_ON_FILE_NOT_FOUND = "failOnFileNotFound";
    String PROP_SCAN_INTERVAL = "scanInterval";
    
    void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;
    void start();
    void shutdown();
}

/**
 * Plugin for logging job execution history
 */
class LoggingJobHistoryPlugin implements SchedulerPlugin {
    String PROP_LOG_NAME = "logName";
    String PROP_JOB_SUCCESS_MESSAGE = "jobSuccessMessage";
    String PROP_JOB_FAILED_MESSAGE = "jobFailedMessage";
    
    void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;
}

/**
 * Plugin for logging trigger firing history
 */
class LoggingTriggerHistoryPlugin implements SchedulerPlugin {
    String PROP_LOG_NAME = "logName";
    String PROP_TRIGGER_FIRED_MESSAGE = "triggerFiredMessage";
    String PROP_TRIGGER_COMPLETE_MESSAGE = "triggerCompleteMessage";
    String PROP_TRIGGER_MISFIRED_MESSAGE = "triggerMisfiredMessage";
}

/**
 * Plugin for graceful shutdown using JVM shutdown hooks
 */
class ShutdownHookPlugin implements SchedulerPlugin {
    String PROP_CLEAN_SHUTDOWN = "cleanShutdown";
    
    void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;
}

Usage Examples:

// JTA Transaction Support
@ExecuteInJTATransaction
public class TransactionalReportJob implements Job {
    public void execute(JobExecutionContext context) throws JobExecutionException {
        // This job will execute within a JTA transaction
        // Any database operations will be part of the transaction
        updateReportData();
        sendNotification();
        // Transaction commits automatically if no exception
    }
}

// Configure JTA in quartz.properties
/*
org.quartz.scheduler.jobFactory.class = org.quartz.ee.jta.JTAAnnotationAwareJobRunShellFactory
org.quartz.scheduler.userTransactionURL = java:comp/UserTransaction
*/

// Servlet Integration
public class MyWebApp extends HttpServlet {
    @Override
    public void init() throws ServletException {
        // Scheduler is automatically initialized by QuartzInitializerListener
        ServletContext context = getServletContext();
        SchedulerFactory factory = (SchedulerFactory) context.getAttribute(
            QuartzInitializerListener.QUARTZ_FACTORY_KEY);
        
        try {
            Scheduler scheduler = factory.getScheduler();
            // Use scheduler in web application
        } catch (SchedulerException e) {
            throw new ServletException(e);
        }
    }
}

// Clustering Configuration (quartz.properties)
/*
# Enable clustering
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000

# Instance configuration
org.quartz.scheduler.instanceName = MyClusteredScheduler
org.quartz.scheduler.instanceId = AUTO

# Database job store required for clustering
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
org.quartz.jobStore.dataSource = myDS
org.quartz.jobStore.tablePrefix = QRTZ_

# Data source configuration
org.quartz.dataSource.myDS.driver = org.postgresql.Driver
org.quartz.dataSource.myDS.URL = jdbc:postgresql://localhost/quartz
org.quartz.dataSource.myDS.user = quartz
org.quartz.dataSource.myDS.password = password
org.quartz.dataSource.myDS.maxConnections = 5
*/

// Email Job Usage
JobDetail emailJob = newJob(SendMailJob.class)
    .withIdentity("emailJob", "notifications")
    .usingJobData(SendMailJob.PROP_SMTP_HOST, "smtp.company.com")
    .usingJobData(SendMailJob.PROP_RECIPIENT, "admin@company.com")
    .usingJobData(SendMailJob.PROP_SENDER, "scheduler@company.com")
    .usingJobData(SendMailJob.PROP_SUBJECT, "Daily Report Ready")
    .usingJobData(SendMailJob.PROP_MESSAGE, "The daily report has been generated and is ready for review.")
    .build();

// File monitoring job
JobDetail fileMonitorJob = newJob(FileScanJob.class)
    .withIdentity("fileMonitor", "system")
    .usingJobData(FileScanJob.FILE_NAME, "/data/incoming/orders.xml")
    .usingJobData(FileScanJob.MINIMUM_UPDATE_AGE, 5000L) // 5 seconds
    .build();

// Plugin configuration in quartz.properties
/*
# XML scheduling data processor plugin
org.quartz.plugin.xmlSchedulingData.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.xmlSchedulingData.fileNames = jobs.xml
org.quartz.plugin.xmlSchedulingData.failOnFileNotFound = true
org.quartz.plugin.xmlSchedulingData.scanInterval = 120

# Job history logging plugin
org.quartz.plugin.jobHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin
org.quartz.plugin.jobHistory.logName = jobHistoryLog

# Shutdown hook plugin
org.quartz.plugin.shutdownHook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownHook.cleanShutdown = true
*/

// JMX Monitoring Setup
Properties props = new Properties();
props.setProperty("org.quartz.scheduler.jmx.export", "true");
props.setProperty("org.quartz.scheduler.jmx.objectName", "quartz:type=QuartzScheduler,name=MyScheduler,instance=NON_CLUSTERED");

SchedulerFactory factory = new StdSchedulerFactory(props);
Scheduler scheduler = factory.getScheduler();

// Now scheduler MBeans are available via JMX
// Can be monitored with JConsole, VisualVM, or custom JMX clients

Configuration Properties

Common Enterprise Configuration

# JTA Configuration
org.quartz.scheduler.jobFactory.class = org.quartz.ee.jta.JTAAnnotationAwareJobRunShellFactory
org.quartz.scheduler.userTransactionURL = java:comp/UserTransaction

# JMX Configuration
org.quartz.scheduler.jmx.export = true
org.quartz.scheduler.jmx.objectName = quartz:type=QuartzScheduler,name=MyScheduler

# Clustering Configuration
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000
org.quartz.scheduler.instanceId = AUTO

# Plugin Configuration
org.quartz.plugin.shutdownHook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownHook.cleanShutdown = true

Install with Tessl CLI

npx tessl i tessl/maven-org-quartz-scheduler--quartz

docs

calendar-management.md

core-scheduling.md

enterprise-features.md

exception-handling.md

index.md

job-management.md

listeners-events.md

matcher-framework.md

persistence-storage.md

schedule-builders.md

trigger-management.md

utilities-helpers.md

tile.json