Scheduler (1)

创建Scheduler一般都是

1
2
3
4
5
6
7
8
9
10
11
12
13
14
package   scheduler;
import   org.junit.Test;
import   org.quartz.*;
import   org.quartz.impl.StdSchedulerFactory;
public   class   SchedulerTest {
     @Test
     public   void   test1(){
         try   {
             Scheduler sc= new   StdSchedulerFactory().getDefaultScheduler();
         }  catch   (SchedulerException e) {
             e.printStackTrace();
         }
     }
}

这种情况下使用的是默认调度器,在quartz.properties中已经把属性全部设置好了,看代码

1
2
3
4
5
6
7
8
9
10
11
12
13
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.rmi.export:  false
org.quartz.scheduler.rmi.proxy:  false
org.quartz.scheduler.wrapJobExecutionInUserTransaction:  false
 
org.quartz.threadPool. class : org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount:  10 //Thread数量
org.quartz.threadPool.threadPriority:  5 //Thread优先级
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread:  true
 
org.quartz.jobStore.misfireThreshold:  60000
  //将schedule相关信息保存在ram中,轻量级速度快,遗憾的是重启应用时会丢失
org.quartz.jobStore. class : org.quartz.simpl.RAMJobSto

我们可以自己配置相关的信息,比如thread的数量

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package   scheduler;
import   java.util.Properties;
//两个quartz包不可以少
import   org.quartz.*;
import   org.quartz.impl.StdSchedulerFactory;
public   class   SchedulerTest {
     private   static   SchedulerFactory scf= new   StdSchedulerFactory();
     static {
         Properties pr= new   Properties();
         //将thread数量设置为50
         pr.put( "org.quartz.threadPool.threadCount" ,  "50" );
         try   {
             ((StdSchedulerFactory) scf).initialize(pr);
         }  catch   (SchedulerException e) {
             e.printStackTrace();
         }
 
     }
}

运行之后,会发现已经thread数量已经变化

1
2
3
4
5
6
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  50   threads.
  Using job-store  'org.quartz.simpl.RAMJobStore'   - which does not support persistence. and is not clustered.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值