`

Quartz之JobBuilder

 
阅读更多
JobBuilder也可向任务传递数据,通常情况下,我们使用它就可向任务类发送数据了,如有特别复杂的传递参数,它提供了一个传递:JobDataMap对象的方法,当然这个要根据个人使用习惯来说了呀  它重载了方法usingJobData(),如下图:

JobDetail job = newJob(StatefulDumbJob.class)
            .withIdentity("statefulJob1", "group1")
            .usingJobData(StatefulDumbJob.EXECUTION_DELAY, 10000L)//传递数据
            .build();
    
        SimpleTrigger trigger = newTrigger() 
            .withIdentity("trigger1", "group1")
            .startAt(startTime)
            .withSchedule(simpleSchedule()
                    .withIntervalInSeconds(3)
                    .repeatForever())
            .build();
        
        Date ft = sched.scheduleJob(job, trigger);
        log.error("任务key: "+job.getKey() + ",执行运行时间: " + sdf.format(ft) +  
                ",触发器重复执行次数: " + trigger.getRepeatCount() + 
                ",触发器执行时间: " + trigger.getRepeatInterval() / 1000 + " seconds");


在任务类一样可取出:
JobDataMap map = context.getJobDetail().getJobDataMap();
        int executeCount = 0;
        if (map.containsKey(NUM_EXECUTIONS)) {
            executeCount = map.getInt(NUM_EXECUTIONS);
        }
        executeCount++;
        map.put(NUM_EXECUTIONS, executeCount);
  • 大小: 11.6 KB
分享到:
评论
1 楼 小鸟的饥渴 2015-05-26  
[color=brown][/color]
trtyrytryt

相关推荐

    定时器quartz的使用方法

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public...

    quartz 实现按天、按周、按月定时任务的简单demo

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public...

    quartz2.1.6

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.impl.StdSchedulerFactory; public...

    maven-quartz(定时任务)最简单版本

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.TriggerBuilder; // 创建...

    quartz-2.2.0.jar.zip

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org....

    quartz使用cron表达式的实例

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerBuilder; JobDetail jobDetail = JobBuilder.newJob(MyJob.class) .withIdentity("myJob", ...

    一个java Quartz的小例子

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.SimpleScheduleBuilder; import org.quartz.Trigger; import ...

    common-quartz.zip

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.context.annotation.Bean; import org.springframework....

    spring-boot-quartz

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.beans.factory.annotation...

    quartz实例sqlserver数据库连接

    IJobDetail job = JobBuilder.Create().Build(); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("myTrigger") .WithCronSchedule("0 * * * * ?") // 每分钟触发 .Build(); scheduler.ScheduleJob...

    spring-boot集成quartz实现动态任务管理,支持集群

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.context.annotation....

    SpringBoot整合Quartz任务定时调度

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.beans.factory.annotation...

    SpringBoot 整合Quartz(集群)实现定时任务调度

    return JobBuilder.newJob(MyTask.class) .withIdentity("myTask", "group1") .build(); } @Bean public CronTrigger myTaskTrigger() { return TriggerBuilder.newTrigger() .withIdentity("myTaskTrigger...

    quartz cronExpression配置说明

    import org.quartz.JobBuilder; import org.quartz.TriggerBuilder; import org.quartz.CronScheduleBuilder; public class QuartzExample { public static void main(String[] args) throws Exception { // 创建...

    Quartz2.2-JobStore持久化到数据库

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.quartz.SchedulerFactory; import org....

    Quartz调度、终止执行的任务

    JobDetail job = JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") // 设置Job的名字和组名 .build(); // 创建Trigger Trigger trigger = TriggerBuilder.newTrigger() .withIdentity(...

    springboot2.3集成quartz定时任务持久化数据库,支持集群

    return JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") .build(); } @Bean public CronTrigger myCronTrigger() { return TriggerBuilder.newTrigger() .withIdentity("myTrigger", ...

    spring-boot-Quartz-1.zip

    import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerBuilder; import org.springframework.context.annotation.Bean; import org.springframework....

    springboot2.0整合quartz

    return JobBuilder.newJob(MyJob.class) .withIdentity("myJob", "group1") // 定义Job的名字和组名 .build(); } @Bean public Trigger myJobTrigger(JobDetail myJob) { return TriggerBuilder.newTrigger...

    Quartz

    ### Java框架介绍: Quartz从入门到进阶 #### 一、Quartz简介 Quartz是一个完全由Java编写的开源作业调度框架,适用于多种Java应用程序环境,包括但不限于J2SE、Web应用以及J2EE应用服务器。它提供了一种简单而灵活...

Global site tag (gtag.js) - Google Analytics