コード例 #1
0
  /** 初始化定时线程池 */
  private void initScheduler() {
    // 根据定时flush时间间隔分类,计算定时线程池大小,并初始化
    final Set<Integer> tmpSet = new HashSet<Integer>();
    for (final String topic : this.metaConfig.getTopics()) {
      final int unflushInterval = this.metaConfig.getTopicConfig(topic).getUnflushInterval();
      tmpSet.add(unflushInterval);
    }
    this.scheduledExecutorService = new ScheduledThreadPoolExecutor(tmpSet.size() + 5);

    try {
      if (DirectSchedulerFactory.getInstance().getAllSchedulers().isEmpty()) {
        DirectSchedulerFactory.getInstance()
            .createVolatileScheduler(this.metaConfig.getQuartzThreadCount());
      }
      this.scheduler = DirectSchedulerFactory.getInstance().getScheduler();
    } catch (final SchedulerException e) {
      throw new ServiceStartupException("Initialize quartz scheduler failed", e);
    }
  }
コード例 #2
0
 /** Initialises the scheduler. */
 public void initProvider() throws CronProviderInitialisationException {
   instanceId = UUID.randomUUID();
   final JobStore jobStore = new RAMJobStore();
   final ThreadPool threadPool = new SimpleThreadPool(4, Thread.NORM_PRIORITY);
   try {
     threadPool.initialize();
   } catch (SchedulerConfigException ex) {
     throw new CronProviderInitialisationException("Error initializing Quartz ThreadPool", ex);
   }
   final DirectSchedulerFactory schedulerFactory = DirectSchedulerFactory.getInstance();
   schedulerName = SCHEDULER_NAME_PREFIX + "_" + instanceId.toString();
   try {
     schedulerFactory.createScheduler(schedulerName, instanceId.toString(), threadPool, jobStore);
     scheduler = schedulerFactory.getScheduler(schedulerName);
     scheduler.start();
   } catch (SchedulerException ex) {
     throw new CronProviderInitialisationException("Error initializing Quartz scheduler", ex);
   }
 }