The JobDataMap can be used to hold any amount of (serializable) data objects which you wish to have made available to the job instance when it executes. JobDataMap is an implementation of the Java Map interface, and has some added convenience methods for storing and retrieving data of primitive types.

Here's some snippets of putting data into the JobDataMap while defining/building the JobDetail, prior to adding the job to the scheduler:

JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
.withIdentity("helloJob", Scheduler.DEFAULT_GROUP)
.usingJobData("msg", "hello JobDataMap.")
.build();

Here is an example of getting data from the JobDataMap during the job's execution:

public class HelloJob implements Job {

    public void execute(JobExecutionContext context) throws JobExecutionException {
String msg = context.getJobDetail().getJobDataMap().getString("msg");
System.out.println("msg: " + msg);
} }

If you add setter methods to your job class that correspond to the names of keys in the JobDataMap (such as a setMsg(String msg) method for the data in the example above), then Quartz's default JobFactory implementation will automatically call those setters when the job is instantiated, thus preventing the need to explicitly get the values out of the map within your execute method.

public class HelloJob implements Job {

    @Setter
private String msg; public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("msg: " + msg);
} }

Quartz Scheduler(2.2.1) - Usage of JobDataMap的更多相关文章

  1. Quartz Scheduler(2.2.1) - Usage of Calendars

    Quartz Calendar objects (not java.util.Calendar objects) can be associated with triggers at the time ...

  2. Quartz Scheduler(2.2.1) - Usage of SimpleTrigger

    SimpleTrigger should meet your scheduling needs if you need to have a job execute exactly once at a ...

  3. Quartz Scheduler(2.2.1) - Usage of CronTriggers

    Cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerfu ...

  4. Table of Contents - Quartz Scheduler

    Getting Started Hello World Integration with Spring Quartz Scheduler Developer Guide Usage of JobDat ...

  5. spring集成quartz scheduler

    创建项目 有两种创建quart配置作业 1.使用MethodInvokingJobDetailFactoryBean  Quartz Scheduler 配置作业(MethodInvokingJobD ...

  6. Quartz Scheduler 开发指南(1)

    Quartz Scheduler 开发指南(1) 原文地址:http://www.quartz-scheduler.org/generated/2.2.2/html/qtz-all/ 实例化调度程序( ...

  7. 最新 Spring 4.2.2 集成 Quartz Scheduler 2.2.2 任务调度示例

    参考http://blog.csdn.net/defonds/article/details/49496895 本文将演示如何通过 Spring 使用 Quartz Scheduler 进行任务调度. ...

  8. Quartz Scheduler(2.2.1) - hello world

    简单示例 1. maven 依赖 <dependencies> <dependency> <groupId>org.quartz-scheduler</gro ...

  9. Quartz Scheduler(2.2.1) - Working with JobStores

    About Job Stores JobStores are responsible for keeping track of all the work data you give to the sc ...

随机推荐

  1. Oracle DB 执行用户管理的备份和恢复

    • 说明用户管理的备份和恢复与服务器管理的备份和恢复 之间的差异 • 执行用户管理的数据库完全恢复 • 执行用户管理的数据库不完全恢复 备份和恢复的使用类型 数据库备份和恢复的类型包括: • 用户管理 ...

  2. java functional syntax overview

    Defining a Functional Interface @FunctionalInterface public interface TailCall<T> { TailCall&l ...

  3. 进入名企必读的.NET面试题

    1. 罗列ASP.NET服务器控件的运行的生命周期. 一般服务器控件的生命周期包含11个阶段: /// <summary> /// 1. 初始化 /// </summary> ...

  4. UVa699 The Falling Leaves

      // UVa699 The Falling Leaves // 题意:给一棵二叉树,每个节点都有一个水平位置:左儿子在它左边1个单位,右儿子在右边1个单位.从左向右输出每个水平位置的所有结点的权值 ...

  5. poj2105 IP Address(简单题)

    题目链接:id=2105">http://poj.org/problem?id=2105 ----------------------------------------------- ...

  6. mysql的top n查询

    我们知道,在ms sql server中或access中,若要查询前10条记录,使用top 10即可,但在mysql中不支持这个写法,它用limit 10.  我们可以利用MySQL中SELECT支持 ...

  7. HDU 4121 Xiangqi 模拟题

    Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...

  8. -_-#【JS】defer / async

    引用JavaScript文件时的两个属性defer和async <script src="js1.js" defer></script> <scrip ...

  9. 将Eclipse中现有的java类生成类图

    需求:将Eclipse中现有的java类生成类图 一:什么是ModelGoon? 它是一个Eclipse插件,用于基于UML图的模型设计,以及逆向工程(即从已有源代码生成类图). 二:安装 下载Mod ...

  10. c语言指针难点

    先来一个例子 例: #include "stdio.h" int main() { ] = {,,,,}; printf("a是一个地址%d\n",a); pr ...