6

Quartz定时任务框架线程池

 2 years ago
source link: https://wakzz.cn/2018/07/19/java/Quartz%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E6%A1%86%E6%9E%B6%E7%BA%BF%E7%A8%8B%E6%B1%A0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Quartz定时任务框架线程池

祈雨的博客
2018-07-19

springboot使用@EnableScheduling注解打开定时任务功能后,默认创建一个固定线程数为1的线程池给定时任务框架调用执行定时任务。

当多个任务同时执行时,会导致多个任务竞争执行线程,当上一个任务执行完毕后,线程才会被释放出来用于其他任务的执行。导致定时任务延时执行。

因此需要创建一个多线程数量的线程池供定时任务使用。

@Configuration
public class ScheduledThreadPoolConfig implements SchedulingConfigurer {

@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
taskRegistrar.setScheduler(taskExecutor());
}

@Bean(name="taskExecutor",destroyMethod="shutdown")
public Executor taskExecutor() {
return Executors.newScheduledThreadPool(20);
}

}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK