Quartz 环境搭建并启动

项目代码:

https://github.com/yuleiqq/quartz_example/tree/master/quartz_study

 

1、利用IDEA 工具搭建一个基本的Java Maven 工程.  并配置依赖包

   pom.xml 配置

<dependencies>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>
    </dependencies>

  log4j.xml  配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <appender name="default" class="org.apache.log4j.ConsoleAppender">
    <param name="target" value="System.out"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c]%n%m%n%n"/>
    </layout>
  </appender>

 <logger name="org.quartz">
   <level value="info" />
 </logger>

    <logger name="com">
        <level value="debug" />
    </logger>

  <root>
    <level value="info" />
    <appender-ref ref="default" />
  </root>

  
</log4j:configuration>

quartz.properties 配置

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

 

写一个Java类

package com.example01;

import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author :  yulei
 * @data :  2020/1/10 14:25
 * @Version :  1.0
 **/

public class SchedulerTest {

   public static Logger log = LoggerFactory.getLogger(SchedulerTest.class);

    public static void main(String[] args) throws SchedulerException {
        //调度器
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        log.debug("调度器名称:"+scheduler.getSchedulerName());

        scheduler.start();
    }


}

运行效果如下:

[INFO] 15 一月 03:31:42.315 下午 main [org.quartz.impl.StdSchedulerFactory]
Using default implementation for ThreadExecutor

[INFO] 15 一月 03:31:42.343 下午 main [org.quartz.core.SchedulerSignalerImpl]
Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl

[INFO] 15 一月 03:31:42.343 下午 main [org.quartz.core.QuartzScheduler]
Quartz Scheduler v.2.3.0 created.

[INFO] 15 一月 03:31:42.345 下午 main [org.quartz.simpl.RAMJobStore]
RAMJobStore initialized.

[INFO] 15 一月 03:31:42.347 下午 main [org.quartz.core.QuartzScheduler]
Scheduler meta-data: Quartz Scheduler (v2.3.0) 'MyScheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 3 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.


[INFO] 15 一月 03:31:42.347 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler 'MyScheduler' initialized from default resource file in Quartz package: 'quartz.properties'

[INFO] 15 一月 03:31:42.347 下午 main [org.quartz.impl.StdSchedulerFactory]
Quartz scheduler version: 2.3.0

[DEBUG] 15 一月 03:31:42.347 下午 main [example01.SchedulerTest]
调度器名称:MyScheduler

[INFO] 15 一月 03:31:42.347 下午 main [org.quartz.core.QuartzScheduler]
Scheduler MyScheduler_$_NON_CLUSTERED started.

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值