• quartz---的jobDateil,Trigger的存值


            quartz---的jobDateil,Trigger的存值

     1 package com.imooc.demo.helloQuartz;
     2 
     3 import java.text.SimpleDateFormat;
     4 import java.util.Date;
     5 
     6 import org.quartz.JobBuilder;
     7 import org.quartz.JobDetail;
     8 import org.quartz.Scheduler;
     9 import org.quartz.SchedulerException;
    10 import org.quartz.SchedulerFactory;
    11 import org.quartz.SimpleScheduleBuilder;
    12 import org.quartz.Trigger;
    13 import org.quartz.TriggerBuilder;
    14 import org.quartz.impl.StdSchedulerFactory;
    15 
    16 public class HelloScheduler {
    17 
    18     public static void main(String[] args) throws SchedulerException {
    19         // 创建一个jobDatail实例,将该实力与helloJob绑定
    20         JobDetail detail = JobBuilder.newJob(HelloJob.class).withIdentity("myJob").usingJobData("message", "hi! myjob")
    21                 .usingJobData("FloatJobValue", 3.14F).build();
    22 
    23         // 创建一个Trigger实例,定义该job立即执行,并且在每隔2秒重复执行
    24         Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1")
    25                 .usingJobData("message", "hi! myTrigger").usingJobData("DoubleTriggerValue", 2.0D).startNow()
    26                 .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(2).repeatForever()).build();
    27         // 创建Scheduler实例
    28         SchedulerFactory factory = new StdSchedulerFactory();
    29         Scheduler scheduler = factory.getScheduler();
    30         scheduler.start();
    31         Date date = new Date();
    32         SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    33         System.out.println("Current Exec Time Is:" + sf.format(date) + "-----");
    34         // 把jobDetail和Trigger与scheuler绑定在一起
    35         scheduler.scheduleJob(detail, trigger);
    36     }
    37 }
     1 package com.imooc.demo.helloQuartz;
     2 
     3 import java.text.SimpleDateFormat;
     4 import java.util.Date;
     5 
     6 import org.quartz.Job;
     7 import org.quartz.JobExecutionContext;
     8 import org.quartz.JobExecutionException;
     9 import org.quartz.JobKey;
    10 import org.quartz.TriggerKey;
    11 
    12 public class HelloJob implements Job {
    13 
    14     private String message;
    15     private Float FloatJobValue;
    16     private Double DoubleTriggerValue;
    17 
    18     public String getMessage() {
    19         return message;
    20     }
    21 
    22     public void setMessage(String message) {
    23         this.message = message;
    24     }
    25 
    26     public Float getFloatJobValue() {
    27         return FloatJobValue;
    28     }
    29 
    30     public void setFloatJobValue(Float floatJobValue) {
    31         FloatJobValue = floatJobValue;
    32     }
    33 
    34     public Double getDoubleTriggerValue() {
    35         return DoubleTriggerValue;
    36     }
    37 
    38     public void setDoubleTriggerValue(Double doubleTriggerValue) {
    39         DoubleTriggerValue = doubleTriggerValue;
    40     }
    41 
    42     @Override
    43     public void execute(JobExecutionContext context) throws JobExecutionException {
    44         // 打印当前执行的时间,格式为2017-05-06 00:00:00
    45         Date date = new Date();
    46         SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    47         System.out.println("Current Exec Time Is:" + sf.format(date));
    48         // 编写具体业务逻辑
    49         // 获取存入HelloScheduler信息
    50         JobKey key = context.getJobDetail().getKey();
    51         System.out.println("My Job name and group are:" + key.getName() + ":" + key.getGroup());
    52 
    53         TriggerKey keys = context.getTrigger().getKey();
    54         System.out.println("My Trigger name and group are:" + keys.getName() + ":" + keys.getGroup());
    55 
    56         //JobDataMap dataMap = context.getMergedJobDataMap();
    57         System.out.println("TriggerDouble:" + DoubleTriggerValue + "
    " + "TriggerMessage:" + message + "
    "
    58                 + "JobFloat:" + FloatJobValue);
    59         System.out.println("-----------------");
    60     }
    61 
    62 }
     1 package com.imooc.demo.helloQuartz;
     2 
     3 import java.text.SimpleDateFormat;
     4 import java.util.Date;
     5 
     6 import org.quartz.Job;
     7 import org.quartz.JobExecutionContext;
     8 import org.quartz.JobExecutionException;
     9 import org.quartz.JobKey;
    10 import org.quartz.TriggerKey;
    11 
    12 public class HelloJob implements Job {
    13 
    14     private String message;
    15     private Float FloatJobValue;
    16     private Double DoubleTriggerValue;
    17 
    18     public String getMessage() {
    19         return message;
    20     }
    21 
    22     public void setMessage(String message) {
    23         this.message = message;
    24     }
    25 
    26     public Float getFloatJobValue() {
    27         return FloatJobValue;
    28     }
    29 
    30     public void setFloatJobValue(Float floatJobValue) {
    31         FloatJobValue = floatJobValue;
    32     }
    33 
    34     public Double getDoubleTriggerValue() {
    35         return DoubleTriggerValue;
    36     }
    37 
    38     public void setDoubleTriggerValue(Double doubleTriggerValue) {
    39         DoubleTriggerValue = doubleTriggerValue;
    40     }
    41 
    42     @Override
    43     public void execute(JobExecutionContext context) throws JobExecutionException {
    44         // 打印当前执行的时间,格式为2017-05-06 00:00:00
    45         Date date = new Date();
    46         SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    47         System.out.println("Current Exec Time Is:" + sf.format(date));
    48         // 编写具体业务逻辑
    49         // 获取存入HelloScheduler信息
    50         JobKey key = context.getJobDetail().getKey();
    51         System.out.println("My Job name and group are:" + key.getName() + ":" + key.getGroup());
    52 
    53         TriggerKey keys = context.getTrigger().getKey();
    54         System.out.println("My Trigger name and group are:" + keys.getName() + ":" + keys.getGroup());
    55 
    56         //JobDataMap dataMap = context.getMergedJobDataMap();
    57         System.out.println("TriggerDouble:" + DoubleTriggerValue + "
    " + "TriggerMessage:" + message + "
    "
    58                 + "JobFloat:" + FloatJobValue);
    59         System.out.println("-----------------");
    60     }
    61 
    62 }

    jobDateil,Trigger的存值,取值。
        1.JobDateMap的取值;
        2.set和get注入方法取值;

  • 相关阅读:
    C++笔记
    mongodb文件损坏的恢复--无可恢复数据
    wiredtiger--初学数据恢复
    mongodb异常恢复
    守护进程,互斥锁, IPC ,Queue队列,生产消费着模型
    进程,多进程,进程与程序的区别,程序运行的三种状态,multiprocessing模块中的Process功能,和join函数,和其他属性,僵尸与孤儿进程
    socket之UDP协议,并发编程介绍,操作系统发展史
    半连接数,粘包问题,自定义报头
    socket模块
    网络编程介绍,C/S 架构,网络通讯协议,osi七层
  • 原文地址:https://www.cnblogs.com/meiLinYa/p/9020244.html
Copyright © 2020-2023  润新知