zoukankan      html  css  js  c++  java
  • java quartz的使用,做时间轮询调用 CronTrigger

    import org.quartz.Job;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    
    public class TestJob implements Job{
    
     public void execute(JobExecutionContext arg0) throws JobExecutionException {
      System.out.println("ok");
     }
    
    }
    <pre name="code" class="html">import java.util.Properties;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.quartz.CronTrigger;
    import org.quartz.JobDetail;
    import org.quartz.Scheduler;
    import org.quartz.Trigger;
    import org.quartz.impl.StdSchedulerFactory;
    
    import com.ai.appframe2.util.ResourceUtil;
    import com.asiainfo.appframe.ext.exeframe.task.TaskFrameWork;
    
    public class NewsVisitCountTask {
     private transient static Log log = LogFactory.getLog(TestTask.class);
     
     public void doTask(String taskCode,String taskID) throws Exception {
      String[] args = new String[]{taskCode,"0",taskID};
      //载入配置參数
         Properties prop = ResourceUtil.loadPropertiesFromClassPath("task/task.properties", "task", true);
      //生成调度
      StdSchedulerFactory scheduler = new StdSchedulerFactory(prop);
      Scheduler schedu = scheduler.getDefaultScheduler();
      //绑定job
      //创建jobDetail实例,绑定Job实现类  
      //指明job的名称,所在组的名称,以及绑定job类  
      JobDetail job = new JobDetail("TaskScanJob", "TaskScanJobGrp", TestJob.class);
      //默认的scanDataJob.cron的參数。每隔1分钟
         String scanDataJobCron = "0 0/1 * * * ?";
         //加入触发器
         Trigger trigger = new CronTrigger("TaskScanTrigger", "TaskScanTriggerGrp", scanDataJobCron);<pre name="code" class="html"> //将任务和触发器加入调度
         schedu.scheduleJob(job, trigger);
         schedu.start();
     }
     public static void main(String[] args) throws Exception {
      NewsVisitCountTask task = new NewsVisitCountTask();
            task.doTask("EMP_STAFF_YEAR_A","1000000002");
            System.out.println("ok");
     }
    }本人才写的源码。这里是公司的须要我才专门研究了一下下,结果发现超级好用
    
    
    
    
    
    
    
                    
  • 相关阅读:
    Leetcode Array 4 Median of Two Sorted Arrays
    vscode Python Pylint(代码检测插件)
    Leetcode Array 1 twoSum
    mysql 配置 安装和 root password 更改
    vscode 编译调试c/c++的环境配置
    chm文件打不开的解决办法
    A + B Problem II
    欢天喜地七仙女——代码规范与计划
    欢天喜地七仙女——项目系统设计与数据库设计
    欢天喜地七仙女——团队Gitee实战训练
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/8573655.html
Copyright © 2011-2022 走看看