2.Quartz - 搭建

作者: 风云雄霸天下123456 | 来源:发表于2017-10-28 17:36 被阅读18次

    参考

    1. Quartz 官方
    2. Quartz教程 - 易百教程

    安装

    • 说明
      1. 其是任务调度框架
      2. 基于Maven
      3. Quartz2
    • 安装
      • 安装包pom
        <dependencies>
          <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
          </dependency>
        </dependencies>
        
      • quartz.properties
        • 路径
          src/main/resources
        • 内容
          org.quartz.scheduler.instanceName = MyScheduler
          org.quartz.threadPool.threadCount = 3
          org.quartz.jobStore.class =org.quartz.simpl.RAMJobStore
          
      • 建立Job(测试Job)
        package com.mingwang.simpleapp;
        
        import org.quartz.Job;
        import org.quartz.JobExecutionContext;
        import org.quartz.JobExecutionException;
        
        public class HelloJob implements Job
        {
            public void execute(JobExecutionContext context)
                    throws JobExecutionException {
        
                System.out.println("Hello Quartz!");
        
            }
        }
        
      • 运行
        package com.mingwang.simpleapp;
        
        import org.quartz.*;
        import org.quartz.impl.StdSchedulerFactory;
        
        /**
         * Created by mingwang on 2017/10/28.
         */
        public class Test {
        
            public static void main(String [] args) {
                quartz();
            }
        
            public static void quartz()
            {
                JobDetail job = JobBuilder.newJob(HelloJob.class)
                        .withIdentity("dummyJobName", "group1").build();
        
                // Trigger the job to run on the next round minute
                Trigger trigger = TriggerBuilder
                        .newTrigger()
                        .withIdentity("dummyTriggerName", "group1")
                        .withSchedule(
                                SimpleScheduleBuilder.simpleSchedule()
                                        .withIntervalInSeconds(5).repeatForever())
                        .build();
        
                // schedule it
                Scheduler scheduler = null;
                try {
                    scheduler = new StdSchedulerFactory().getScheduler();
                    scheduler.start();
                    scheduler.scheduleJob(job, trigger);
                } catch (Exception e) {
        
                }
            }
        }
        

    相关文章

      网友评论

        本文标题:2.Quartz - 搭建

        本文链接:https://www.haomeiwen.com/subject/ipuspxtx.html