• 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
  • 相关阅读:
    [Tips] 树莓派VNC登录
    [Tips] 联通宽带+华为路由器,如何进行NAT
    [Tips] 树莓派4B 风扇安装
    [Tips] 家庭树莓派,如何外网访问
    [Tips] 命令行获取设备的外网IP
    MySQL 如何让自增id设置为从1开始
    MySQL报错:Packet for query is too large (2,588 > 2,048).
    Java 实现 Timstamp 和 String 互相转换
    MySQL修改 mysql-bin 日志保存天数以及文件大小限制
    Linux Shell 中的年月日 时分秒
  • 原文地址:https://www.cnblogs.com/lyftest/p/9105727.html
Copyright © 2020-2023  润新知