add schedule config
This commit is contained in:
parent
518ee9f7f5
commit
2f3631cc91
@ -1,20 +1,20 @@
|
||||
package top.baogutang.admin.config;
|
||||
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SaTokenConfigure {
|
||||
/**
|
||||
* 重写 Sa-Token 框架内部算法策略
|
||||
*/
|
||||
@Autowired
|
||||
public void rewriteSaStrategy() {
|
||||
// 重写 Token 生成策略
|
||||
SaStrategy.me.createToken = (loginId, loginType) -> {
|
||||
return SaFoxUtil.getRandomString(60);
|
||||
};
|
||||
}
|
||||
}
|
||||
//package top.baogutang.admin.config;
|
||||
//
|
||||
//import cn.dev33.satoken.strategy.SaStrategy;
|
||||
//import cn.dev33.satoken.util.SaFoxUtil;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//
|
||||
//@Configuration
|
||||
//public class SaTokenConfigure {
|
||||
// /**
|
||||
// * 重写 Sa-Token 框架内部算法策略
|
||||
// */
|
||||
// @Autowired
|
||||
// public void rewriteSaStrategy() {
|
||||
// // 重写 Token 生成策略
|
||||
// SaStrategy.me.createToken = (loginId, loginType) -> {
|
||||
// return SaFoxUtil.getRandomString(60);
|
||||
// };
|
||||
// }
|
||||
//}
|
||||
|
||||
@ -20,22 +20,36 @@ public class ExecutorConfig {
|
||||
@Value("${spring.application.name}")
|
||||
private String appName;
|
||||
|
||||
@Value("${thread.pool.core.pool.size:10}")
|
||||
@Value("${thread.pool.core.pool.size:5}")
|
||||
private Integer corePoolSize;
|
||||
|
||||
@Value("${thread.pool.max.pool.size:20}")
|
||||
@Value("${thread.pool.max.pool.size:10}")
|
||||
private Integer maxPoolSize;
|
||||
|
||||
@Value("${thread.pool.keep.alive.second:10}")
|
||||
private Integer keepAliveSecond;
|
||||
|
||||
@Value("${thread.pool.queue.capacity:200}")
|
||||
@Value("${thread.pool.queue.capacity:100}")
|
||||
private Integer queueCapacity;
|
||||
|
||||
@Bean("commonExecutor")
|
||||
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
|
||||
public ThreadPoolTaskExecutor commonExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setThreadNamePrefix(appName);
|
||||
executor.setThreadNamePrefix(appName + "-common-");
|
||||
executor.setCorePoolSize(corePoolSize);
|
||||
executor.setMaxPoolSize(maxPoolSize);
|
||||
executor.setKeepAliveSeconds(keepAliveSecond);
|
||||
executor.setQueueCapacity(queueCapacity);
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean("scheduleExecutor")
|
||||
public ThreadPoolTaskExecutor scheduleExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setThreadNamePrefix(appName + "-schedule-");
|
||||
executor.setCorePoolSize(corePoolSize);
|
||||
executor.setMaxPoolSize(maxPoolSize);
|
||||
executor.setKeepAliveSeconds(keepAliveSecond);
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package top.baogutang.common.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @description: 定时调度任务线程配置
|
||||
* @author: nikooh
|
||||
* @date: 2024/01/09 : 17:56
|
||||
*/
|
||||
@Configuration
|
||||
public class ScheduleConfig implements SchedulingConfigurer {
|
||||
|
||||
@Resource(name = "scheduleExecutor")
|
||||
private ThreadPoolTaskExecutor scheduleExecutor;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
||||
scheduledTaskRegistrar.setScheduler(scheduleExecutor);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user