mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
添加 Spring Task配置
This commit is contained in:
parent
b8bfce490b
commit
55c9b0c37a
@ -0,0 +1,31 @@
|
||||
package cn.hutool.extra.spring.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* 可自行配置任务线程池, 修改默认参数
|
||||
*
|
||||
* @author JC
|
||||
* @date 03/13
|
||||
*/
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class SpringCronConfig {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(value = TaskScheduler.class)
|
||||
public TaskScheduler taskScheduler() {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
// 任务线程池初始化
|
||||
scheduler.setThreadNamePrefix("TaskScheduler-");
|
||||
scheduler.setPoolSize(Runtime.getRuntime().availableProcessors() / 3 + 1);
|
||||
|
||||
// 保证能立刻丢弃运行中的任务
|
||||
scheduler.setRemoveOnCancelPolicy(true);
|
||||
return scheduler;
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
# Auto Configure
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.hutool.extra.spring.SpringUtil
|
||||
cn.hutool.extra.spring.SpringUtil,\
|
||||
cn.hutool.extra.spring.config.SpringCronConfig
|
||||
|
Loading…
x
Reference in New Issue
Block a user