or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

calendar-management.mdcore-scheduling.mdenterprise-features.mdexception-handling.mdindex.mdjob-management.mdlisteners-events.mdmatcher-framework.mdpersistence-storage.mdschedule-builders.mdtrigger-management.mdutilities-helpers.md

enterprise-features.mddocs/

0

# Enterprise Features

1

2

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.

3

4

## Capabilities

5

6

### JTA Transaction Support

7

8

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

9

10

```java { .api }

11

/**

12

* Annotation to mark jobs that should execute within JTA transactions

13

*/

14

@Target(ElementType.TYPE)

15

@Retention(RetentionPolicy.RUNTIME)

16

@interface ExecuteInJTATransaction {

17

}

18

```

19

20

**JTA Components:**

21

22

```java { .api }

23

/**

24

* Job run shell that executes jobs within JTA transactions

25

*/

26

class JTAJobRunShell extends JobRunShell {

27

JTAJobRunShell(Scheduler scheduler, TriggerFiredBundle firedBundle);

28

}

29

30

/**

31

* Factory for creating JTA-aware job run shells

32

*/

33

class JTAJobRunShellFactory implements JobRunShellFactory {

34

void initialize(Scheduler scheduler) throws SchedulerConfigException;

35

JobRunShell createJobRunShell(TriggerFiredBundle bundle) throws SchedulerException;

36

}

37

38

/**

39

* Annotation-aware JTA job run shell factory

40

*/

41

class JTAAnnotationAwareJobRunShellFactory extends JTAJobRunShellFactory {

42

// Automatically detects @ExecuteInJTATransaction annotation

43

}

44

45

/**

46

* Utility for JTA UserTransaction operations

47

*/

48

class UserTransactionHelper {

49

UserTransaction lookupUserTransaction() throws NamingException;

50

void returnUserTransaction(UserTransaction userTransaction);

51

}

52

```

53

54

### Servlet Integration

55

56

Integration components for web applications and servlet containers.

57

58

```java { .api }

59

/**

60

* Servlet for initializing Quartz scheduler in web applications

61

*/

62

class QuartzInitializerServlet extends HttpServlet {

63

// Init parameters:

64

String SERVLET_CONTEXT_FACTORY_KEY = "quartz:servlet-context-factory-key";

65

String SHUTDOWN_ON_UNLOAD = "shutdown-on-unload";

66

String START_SCHEDULER_ON_LOAD = "start-scheduler-on-load";

67

String WAIT_ON_SHUTDOWN = "wait-on-shutdown";

68

69

void init(ServletConfig cfg) throws ServletException;

70

void destroy();

71

}

72

73

/**

74

* Context listener for initializing Quartz in web applications

75

*/

76

class QuartzInitializerListener implements ServletContextListener {

77

String QUARTZ_FACTORY_KEY = "org.quartz.impl.StdSchedulerFactory.KEY";

78

79

void contextInitialized(ServletContextEvent sce);

80

void contextDestroyed(ServletContextEvent sce);

81

}

82

```

83

84

### JMX Monitoring and Management

85

86

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

87

88

```java { .api }

89

/**

90

* Management server interface for scheduler monitoring

91

*/

92

interface ManagementServer {

93

void start() throws Exception;

94

void stop() throws Exception;

95

boolean isStarted();

96

int getPort();

97

String getAddress();

98

}

99

100

/**

101

* Configuration for REST-based management services

102

*/

103

class ManagementRESTServiceConfiguration {

104

String getBind();

105

void setBind(String bind);

106

107

boolean isEnabled();

108

void setEnabled(boolean enabled);

109

110

String getSecurityServiceLocation();

111

void setSecurityServiceLocation(String securityServiceLocation);

112

113

String getSslBind();

114

void setSslBind(String sslBind);

115

116

boolean isNeedClientAuth();

117

void setNeedClientAuth(boolean needClientAuth);

118

}

119

```

120

121

### Clustering Support

122

123

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

124

125

**Configuration Properties:**

126

```java { .api }

127

/**

128

* Key clustering configuration properties for quartz.properties

129

*/

130

interface ClusteringProperties {

131

// Enable clustering

132

String PROP_CLUSTERED = "org.quartz.jobStore.isClustered";

133

134

// Cluster check-in interval (milliseconds)

135

String PROP_CLUSTER_CHECKIN_INTERVAL = "org.quartz.jobStore.clusterCheckinInterval";

136

137

// Maximum time before instance is considered failed

138

String PROP_CLUSTER_CHECKIN_INTERVAL_RECOVERY = "org.quartz.jobStore.clusterCheckinIntervalRecovery";

139

140

// Unique instance ID within cluster

141

String PROP_INSTANCE_ID = "org.quartz.scheduler.instanceId";

142

143

// Instance name (same across cluster)

144

String PROP_INSTANCE_NAME = "org.quartz.scheduler.instanceName";

145

146

// Auto-generate instance ID

147

String PROP_INSTANCE_ID_GENERATOR_CLASS = "org.quartz.scheduler.instanceIdGenerator.class";

148

}

149

```

150

151

**Clustering Requirements:**

152

- Database-backed JobStore (JDBC)

153

- Synchronized system clocks across nodes

154

- Unique instance IDs per node

155

- Same quartz.properties across cluster

156

157

### Specialized Job Implementations

158

159

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

160

161

```java { .api }

162

/**

163

* Base class for jobs that invoke methods on stateless session beans

164

*/

165

abstract class EJBInvokerJob implements Job {

166

String EJB_JNDI_NAME_KEY = "ejb";

167

String EJB_METHOD_KEY = "method";

168

String EJB_ARGS_KEY = "args";

169

String EJB_ARG_TYPES_KEY = "argTypes";

170

171

void execute(JobExecutionContext context) throws JobExecutionException;

172

}

173

174

/**

175

* Job for invoking EJB 3.0 stateless session beans

176

*/

177

class EJB3InvokerJob extends EJBInvokerJob {

178

// Supports EJB 3.0 annotations and dependency injection

179

}

180

181

/**

182

* Job for sending JMS queue messages

183

*/

184

class SendQueueMessageJob implements Job {

185

String JMS_CONNECTION_FACTORY_JNDI = "connection_factory";

186

String JMS_DESTINATION_JNDI = "destination";

187

String JMS_USE_TXN = "use_txn";

188

String JMS_ACK_MODE = "ack_mode";

189

String JMS_MSG_FACTORY_CLASS_NAME = "msg_factory_class_name";

190

191

void execute(JobExecutionContext context) throws JobExecutionException;

192

}

193

194

/**

195

* Job for sending JMS topic messages

196

*/

197

class SendTopicMessageJob extends SendQueueMessageJob {

198

// Inherits queue functionality, targets topics

199

}

200

201

/**

202

* Job for sending email messages

203

*/

204

class SendMailJob implements Job {

205

String PROP_SMTP_HOST = "smtp_host";

206

String PROP_RECIPIENT = "recipient";

207

String PROP_SENDER = "sender";

208

String PROP_SUBJECT = "subject";

209

String PROP_MESSAGE = "message";

210

String PROP_CHARSET = "charset";

211

212

void execute(JobExecutionContext context) throws JobExecutionException;

213

}

214

215

/**

216

* Job for invoking operations on JMX MBeans

217

*/

218

class JMXInvokerJob implements Job {

219

String JMX_OBJECTNAME = "jmx_objectname";

220

String JMX_METHOD = "jmx_method";

221

String JMX_METHOD_PARAMS = "jmx_method_params";

222

String JMX_METHOD_TYPES = "jmx_method_types";

223

224

void execute(JobExecutionContext context) throws JobExecutionException;

225

}

226

227

/**

228

* Job for monitoring file system changes

229

*/

230

class FileScanJob implements Job {

231

String FILE_NAME = "FILE_NAME";

232

String FILE_SCAN_LISTENER_NAME = "FILE_SCAN_LISTENER_NAME";

233

String MINIMUM_UPDATE_AGE = "MINIMUM_UPDATE_AGE";

234

235

void execute(JobExecutionContext context) throws JobExecutionException;

236

}

237

238

/**

239

* Job for monitoring directory changes

240

*/

241

class DirectoryScanJob extends FileScanJob {

242

// Monitors entire directories for changes

243

}

244

245

/**

246

* No-operation job for testing and placeholder purposes

247

*/

248

class NoOpJob implements Job {

249

void execute(JobExecutionContext context) throws JobExecutionException {

250

// Intentionally does nothing

251

}

252

}

253

```

254

255

### Plugin System

256

257

Extensible plugin architecture for adding custom functionality to schedulers.

258

259

```java { .api }

260

/**

261

* Interface for scheduler plugins

262

*/

263

interface SchedulerPlugin {

264

/**

265

* Initialize the plugin

266

* @param name the plugin name

267

* @param scheduler the scheduler instance

268

* @throws SchedulerConfigException if initialization fails

269

*/

270

void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;

271

272

/**

273

* Start the plugin

274

*/

275

void start();

276

277

/**

278

* Shutdown the plugin

279

*/

280

void shutdown();

281

}

282

283

/**

284

* Plugin for loading job and trigger definitions from XML

285

*/

286

class XMLSchedulingDataProcessorPlugin implements SchedulerPlugin {

287

String PROP_FILE_NAMES = "fileNames";

288

String PROP_FAIL_ON_FILE_NOT_FOUND = "failOnFileNotFound";

289

String PROP_SCAN_INTERVAL = "scanInterval";

290

291

void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;

292

void start();

293

void shutdown();

294

}

295

296

/**

297

* Plugin for logging job execution history

298

*/

299

class LoggingJobHistoryPlugin implements SchedulerPlugin {

300

String PROP_LOG_NAME = "logName";

301

String PROP_JOB_SUCCESS_MESSAGE = "jobSuccessMessage";

302

String PROP_JOB_FAILED_MESSAGE = "jobFailedMessage";

303

304

void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;

305

}

306

307

/**

308

* Plugin for logging trigger firing history

309

*/

310

class LoggingTriggerHistoryPlugin implements SchedulerPlugin {

311

String PROP_LOG_NAME = "logName";

312

String PROP_TRIGGER_FIRED_MESSAGE = "triggerFiredMessage";

313

String PROP_TRIGGER_COMPLETE_MESSAGE = "triggerCompleteMessage";

314

String PROP_TRIGGER_MISFIRED_MESSAGE = "triggerMisfiredMessage";

315

}

316

317

/**

318

* Plugin for graceful shutdown using JVM shutdown hooks

319

*/

320

class ShutdownHookPlugin implements SchedulerPlugin {

321

String PROP_CLEAN_SHUTDOWN = "cleanShutdown";

322

323

void initialize(String name, Scheduler scheduler) throws SchedulerConfigException;

324

}

325

```

326

327

**Usage Examples:**

328

329

```java

330

// JTA Transaction Support

331

@ExecuteInJTATransaction

332

public class TransactionalReportJob implements Job {

333

public void execute(JobExecutionContext context) throws JobExecutionException {

334

// This job will execute within a JTA transaction

335

// Any database operations will be part of the transaction

336

updateReportData();

337

sendNotification();

338

// Transaction commits automatically if no exception

339

}

340

}

341

342

// Configure JTA in quartz.properties

343

/*

344

org.quartz.scheduler.jobFactory.class = org.quartz.ee.jta.JTAAnnotationAwareJobRunShellFactory

345

org.quartz.scheduler.userTransactionURL = java:comp/UserTransaction

346

*/

347

348

// Servlet Integration

349

public class MyWebApp extends HttpServlet {

350

@Override

351

public void init() throws ServletException {

352

// Scheduler is automatically initialized by QuartzInitializerListener

353

ServletContext context = getServletContext();

354

SchedulerFactory factory = (SchedulerFactory) context.getAttribute(

355

QuartzInitializerListener.QUARTZ_FACTORY_KEY);

356

357

try {

358

Scheduler scheduler = factory.getScheduler();

359

// Use scheduler in web application

360

} catch (SchedulerException e) {

361

throw new ServletException(e);

362

}

363

}

364

}

365

366

// Clustering Configuration (quartz.properties)

367

/*

368

# Enable clustering

369

org.quartz.jobStore.isClustered = true

370

org.quartz.jobStore.clusterCheckinInterval = 20000

371

372

# Instance configuration

373

org.quartz.scheduler.instanceName = MyClusteredScheduler

374

org.quartz.scheduler.instanceId = AUTO

375

376

# Database job store required for clustering

377

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

378

org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate

379

org.quartz.jobStore.dataSource = myDS

380

org.quartz.jobStore.tablePrefix = QRTZ_

381

382

# Data source configuration

383

org.quartz.dataSource.myDS.driver = org.postgresql.Driver

384

org.quartz.dataSource.myDS.URL = jdbc:postgresql://localhost/quartz

385

org.quartz.dataSource.myDS.user = quartz

386

org.quartz.dataSource.myDS.password = password

387

org.quartz.dataSource.myDS.maxConnections = 5

388

*/

389

390

// Email Job Usage

391

JobDetail emailJob = newJob(SendMailJob.class)

392

.withIdentity("emailJob", "notifications")

393

.usingJobData(SendMailJob.PROP_SMTP_HOST, "smtp.company.com")

394

.usingJobData(SendMailJob.PROP_RECIPIENT, "admin@company.com")

395

.usingJobData(SendMailJob.PROP_SENDER, "scheduler@company.com")

396

.usingJobData(SendMailJob.PROP_SUBJECT, "Daily Report Ready")

397

.usingJobData(SendMailJob.PROP_MESSAGE, "The daily report has been generated and is ready for review.")

398

.build();

399

400

// File monitoring job

401

JobDetail fileMonitorJob = newJob(FileScanJob.class)

402

.withIdentity("fileMonitor", "system")

403

.usingJobData(FileScanJob.FILE_NAME, "/data/incoming/orders.xml")

404

.usingJobData(FileScanJob.MINIMUM_UPDATE_AGE, 5000L) // 5 seconds

405

.build();

406

407

// Plugin configuration in quartz.properties

408

/*

409

# XML scheduling data processor plugin

410

org.quartz.plugin.xmlSchedulingData.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin

411

org.quartz.plugin.xmlSchedulingData.fileNames = jobs.xml

412

org.quartz.plugin.xmlSchedulingData.failOnFileNotFound = true

413

org.quartz.plugin.xmlSchedulingData.scanInterval = 120

414

415

# Job history logging plugin

416

org.quartz.plugin.jobHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin

417

org.quartz.plugin.jobHistory.logName = jobHistoryLog

418

419

# Shutdown hook plugin

420

org.quartz.plugin.shutdownHook.class = org.quartz.plugins.management.ShutdownHookPlugin

421

org.quartz.plugin.shutdownHook.cleanShutdown = true

422

*/

423

424

// JMX Monitoring Setup

425

Properties props = new Properties();

426

props.setProperty("org.quartz.scheduler.jmx.export", "true");

427

props.setProperty("org.quartz.scheduler.jmx.objectName", "quartz:type=QuartzScheduler,name=MyScheduler,instance=NON_CLUSTERED");

428

429

SchedulerFactory factory = new StdSchedulerFactory(props);

430

Scheduler scheduler = factory.getScheduler();

431

432

// Now scheduler MBeans are available via JMX

433

// Can be monitored with JConsole, VisualVM, or custom JMX clients

434

```

435

436

## Configuration Properties

437

438

### Common Enterprise Configuration

439

440

```properties

441

# JTA Configuration

442

org.quartz.scheduler.jobFactory.class = org.quartz.ee.jta.JTAAnnotationAwareJobRunShellFactory

443

org.quartz.scheduler.userTransactionURL = java:comp/UserTransaction

444

445

# JMX Configuration

446

org.quartz.scheduler.jmx.export = true

447

org.quartz.scheduler.jmx.objectName = quartz:type=QuartzScheduler,name=MyScheduler

448

449

# Clustering Configuration

450

org.quartz.jobStore.isClustered = true

451

org.quartz.jobStore.clusterCheckinInterval = 20000

452

org.quartz.scheduler.instanceId = AUTO

453

454

# Plugin Configuration

455

org.quartz.plugin.shutdownHook.class = org.quartz.plugins.management.ShutdownHookPlugin

456

org.quartz.plugin.shutdownHook.cleanShutdown = true

457

```