Quartz作业无法使用减少的线程数

我想配置分配给正在调用Spring Data方法的Quartz Scheduler作业的线程数。

配置类如下:

@Configuration
public class QuartzConfiguration {

  @Bean
  public JobDetail verificationTokenRemoverJobDetails() {
    return
        JobBuilder
            .newJob(VerificationTokenQuartzRemoverJob.class)
            .withIdentity("Job for verification token remover")
            .storeDurably()
            .build();
  }

  @Bean
  public Trigger verificationTokenRemoverJobTrigger(JobDetail jobDetail) {
    return
        TriggerBuilder
            .newTrigger()
            .forJob(jobDetail)
            .withIdentity("Trigger for verification token remover")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * ? * * *"))
            .build();
  }

  @Bean
  public SchedulerFactoryBean schedulerFactoryBean() {
    SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
    Properties quartzProperties = new Properties();
    quartzProperties.put("org.quartz.threadPool.threadCount","1");
    quartzProperties.put("spring.quartz.job-store-type","jdbc");
    quartzProperties.put("spring.quartz.properties.org.quartz.jobStore.isClustered","true");
    quartzProperties.put("spring.quartz.properties.org.quartz.scheduler.instanceId","AUTO");
    scheduler.setQuartzProperties(quartzProperties);
    return scheduler;
  }
}

我的工作类别如下:

@AllArgsConstructor
@DisallowConcurrentExecution
public class VerificationTokenQuartzRemoverJob implements Job {

  private VerificationTokenRepository verificationTokenRepository;
  private QuartzProperties quartzProperties;

  @Override
  public void execute(JobExecutionContext context) {
    verificationTokenRepository.deleteAllByCreatedLessThan(
        now().minusMinutes(parseLong(quartzProperties.getVerificationTokensOlderThan())));
  }
}

问题是我决定减少作业执行时使用的线程数,因为从我的角度来看,默认数10太多了。我添加了bean public SchedulerFactoryBean schedulerFactoryBean(),它减少了中途获胜的线程数,例如:

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 1 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

这似乎应该可以工作,但是尽管有CRON表达式(每隔两秒钟),但该工作根本没有启动,并且应用程序处于空闲状态。如果我要注释掉第三个配置bean作业,则可以再次使用IntelliJ运行窗口中的信息,但有10个线程,这是不希望的。

我要实现的就是将Quartz Job配置为在指定数量的线程上工作。而且,我想知道如何正确配置Quartz机制,因为据我了解

@Bean
public SchedulerFactoryBean schedulerFactoryBean()

将导致每个Quartz作业都允许单线程,因此,以防万一将来我有多个作业可能导致冲突,不是吗?我将非常感谢您提供有关达到目标和配置Quartz的建议。

h593668654 回答:Quartz作业无法使用减少的线程数

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3151578.html

大家都在问