zoukankan      html  css  js  c++  java
  • quartz 中的线程池

    书接上回:https://www.cnblogs.com/silenceshining/p/15390887.html

    定时器要调度多个定时任务,就得有一个线程池来进行任务的并发处理,那来看下quartz中的线程池情况。

     SchedulerFactory schedulerFactory = new StdSchedulerFactory();
     Scheduler scheduler = schedulerFactory.getScheduler();

    当执行schedulerFactory.getScheduler()时,会初始化一个线程池SimpleThreadPool,过程如下:

    // Get ThreadPool Properties
            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
            String tpClass = cfg.getStringProperty(PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
    
            if (tpClass == null) {
                initException = new SchedulerException(
                        "ThreadPool class not specified. ");
                throw initException;
            }
    
            try {
                tp = (ThreadPool) loadHelper.loadClass(tpClass).newInstance();
            } catch (Exception e) {
                initException = new SchedulerException("ThreadPool class '"
                        + tpClass + "' could not be instantiated.", e);
                throw initException;
            }

    SimpleThreadPool是一个比较简单的线程池实现,只有线程数这一个属性,不像其他功能比较丰富的线程池有像核心线程数、最大线程数、队列大小等参数。

    默认线程数为10,实际运行起来的情况如下截图:

     那如何修改线程数呢?

    可采用如下方式:

     Properties prop = new Properties();
            // 线程池配置
            prop.put("org.quartz.threadPool.threadCount", "20");
            SchedulerFactory schedulerFactory = new StdSchedulerFactory(prop);
            Scheduler scheduler = schedulerFactory.getScheduler();

    那如何定义一个功能比较丰富的线程池给quartz使用呢(当然很少这样哈)

    以下为网上看到的一个参考实现,连接如下,感谢分享:https://gist.github.com/jarek-przygodzki/7991992

  • 相关阅读:
    Hibernate延迟加载、三种状态、脏检查 缓存
    Hibernate入门案例
    Hibernate入门案例及增删改查
    PasswordHelper 对user对象的password进行加密重设
    shrio 加密/编码
    shrio int配置
    shrio 授权
    JUnit中assertEquals和assertSame方法的不同
    shrio 身份认证流程-Realm
    shrio 登录/退出
  • 原文地址:https://www.cnblogs.com/silenceshining/p/15769066.html
Copyright © 2011-2022 走看看