zoukankan      html  css  js  c++  java
  • Quartz使用二 通过属性传递数据

    上一篇介绍了通过context.getJobDetail().getJobDataMap()方式获取传递的数据,其实可以通过定义属性来传递参数

    package org.tonny.quartz;
    
    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    
    public class ThirdJob implements Job
    {
    
        // 通过set,get形式获取jobdetail传递的参数
        private String name;
        private double height;
    
        @Override
        public void execute(JobExecutionContext context) throws JobExecutionException
        {
            /**
             * 执行具体的任务
             */
            // 获取传递的参数
            System.out.println(name);
            System.out.println(height);
        }
    
        public String getName()
        {
            return name;
        }
    
        public void setName(String name)
        {
            this.name = name;
        }
    
        public double getHeight()
        {
            return height;
        }
    
        public void setHeight(double height)
        {
            this.height = height;
        }
    
    }

    调度器中传输数据

    // 创建一个JobDetail实例,将该实例与HelloJob Class绑定
            JobDetail jobDetail = JobBuilder
                    .newJob(ThirdJob.class)
                    .withIdentity("ThirdJob", "ThirdGroup")
                    .usingJobData("name", "北堂一刀")
                    .usingJobData("height", 175.0D)
                    .build();
            
  • 相关阅读:
    七牛云李意扬:如何收集 Go 实时覆盖率丨ECUG Meetup 回顾
    OpenTelemetry 微服务链路追踪
    空接口
    安全规则集合
    采用最快回应
    Golang单元测试实战
    源码 kratos 配置热加载分析
    烟花 光影
    控制Repeater显示列数
    基本代码安全知识
  • 原文地址:https://www.cnblogs.com/supertonny/p/7192245.html
Copyright © 2011-2022 走看看