zoukankan      html  css  js  c++  java
  • quartz--关于Scheduler

      调度器的生命周期,起始于SchedulerFactory的创建,终止于调用shutdown方法。当调度器接口实例创建完成后,就可以添加,删除和查询Jobs和Triggers对象,也可以执行其它的跟调度器相关的操作,比如中止触发器的触发。并且,调度器在调用start方法之前,不会触发任何一个触发器去执行作业任务。

    Scheduler就是Quartz的大脑,所有任务都是由它来设施。

    Schduelr包含两个重要组件: JobStoreThreadPool

    JobStore是会来存储运行时信息的,包括Trigger,Schduler,JobDetail,业务锁等。它有多种实现RAMJobStore(内存实现),JobStoreTX(JDBC,事务由Quartz管理),JobStoreCMT(JDBC,使用容器事务),ClusteredJobStore(集群实现)、TerracottaJobStore。

    ThreadPool就是线程池,Quartz有自己的线程池实现。所有任务的都会由线程池执行。

    SchdulerFactory,顾名思义就是来用创建Schduler了,有两个实现:DirectSchedulerFactory和 StdSchdulerFactory。前者可以用来在代码里定制你自己的Schduler参数。后者是直接读取classpath下的quartz.properties(不存在就都使用默认值)配置来实例化Schduler。通常来讲,我们使用StdSchdulerFactory也就足够了。

    SchdulerFactory本身是支持创建RMI stub的,可以用来管理远程的Scheduler,功能与本地一样,可以远程提交个Job什么的。

       /**
         * Same as
         * {@link DirectSchedulerFactory#createScheduler(ThreadPool threadPool, JobStore jobStore)},
         * with the addition of specifying the scheduler name and instance ID. This
         * scheduler can only be retrieved via
         * {@link DirectSchedulerFactory#getScheduler(String)}
         *
         * @param schedulerName
         *          The name for the scheduler.
         * @param schedulerInstanceId
         *          The instance ID for the scheduler.
         * @param threadPool
         *          The thread pool for executing jobs
         * @param jobStore
         *          The type of job store
         * @throws SchedulerException
         *           if initialization failed
         */
        public void createScheduler(String schedulerName,
                String schedulerInstanceId, ThreadPool threadPool, JobStore jobStore)
            throws SchedulerException;

    StdSchdulerFactory的配置例子, 更多配置,参考Quartz配置指南

    org.quartz.scheduler.instanceName = DefaultQuartzScheduler
    org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
    org.quartz.threadPool.threadCount = 10 
    org.quartz.threadPool.threadPriority = 5
    org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
    org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
  • 相关阅读:
    使用Idea第一次创建一个Mavne工程时没有src目录
    (转)Idea使用教程以及各种问题解决
    'mvn' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    对于synchronized的理解
    聚簇索引和非聚簇索引的区别
    Mysql的两种存储引擎以及区别
    [期末复习]《语义网与知识图谱》期末复习(二)
    [期末复习]《语义网与知识图谱》期末复习(一)
    [论文理解] Attentional Pooling for Action Recognition
    [论文理解] CapsuleNet
  • 原文地址:https://www.cnblogs.com/lyftest/p/9105727.html
Copyright © 2011-2022 走看看