zoukankan      html  css  js  c++  java
  • Quartz Scheduler(2.2.1)

    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);
        }
        
    }
  • 相关阅读:
    memcached与.NET的融合使用(二)
    memcached与.NET的融合使用(一)
    使用window2003安装邮件服务器最新实际操作记录
    2014 -> 2015
    数据挖掘入门 资料和步骤
    CSDN 论坛招聘区是不是有潜规则?在Cnblog招个人试试...
    C#薪水和前途
    面试准备
    面试准备
    面试准备
  • 原文地址:https://www.cnblogs.com/huey/p/5106117.html
Copyright © 2011-2022 走看看