mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-07 01:18:33 +08:00
修复,异步短信无法获取线程池问题
This commit is contained in:
parent
d07676370c
commit
a5adf2afdb
@ -63,7 +63,7 @@ public abstract class SmsFactory {
|
||||
* @author :Wind
|
||||
*/
|
||||
public static void createSmsBlend(SmsReadConfig smsReadConfig, String configId) {
|
||||
BaseConfig supplierConfig = smsReadConfig.getSupplierConfig(configId);
|
||||
SupplierConfig supplierConfig = (SupplierConfig)smsReadConfig.getSupplierConfig(configId);
|
||||
supplierConfig.setConfigId(configId);
|
||||
SmsBlend smsBlend = create(supplierConfig);
|
||||
register(smsBlend);
|
||||
@ -81,7 +81,7 @@ public abstract class SmsFactory {
|
||||
public static void createSmsBlend(SmsReadConfig smsReadConfig) {
|
||||
List<BaseConfig> supplierConfigList = smsReadConfig.getSupplierConfigList();
|
||||
supplierConfigList.forEach(supplierConfig -> {
|
||||
SmsBlend smsBlend = create(supplierConfig);
|
||||
SmsBlend smsBlend = create((SupplierConfig)supplierConfig);
|
||||
register(smsBlend);
|
||||
});
|
||||
}
|
||||
|
||||
@ -54,6 +54,19 @@ public class BeanFactory {
|
||||
}
|
||||
|
||||
public static Executor getExecutor() {
|
||||
if (executor == null){
|
||||
// 创建一个线程池对象
|
||||
ThreadPoolExecutor ex = new ThreadPoolExecutor(
|
||||
smsConfig.getCorePoolSize(),
|
||||
smsConfig.getMaxPoolSize(),
|
||||
smsConfig.getQueueCapacity(),
|
||||
TimeUnit.SECONDS,
|
||||
new ArrayBlockingQueue<>(smsConfig.getMaxPoolSize())
|
||||
);
|
||||
// 线程池对拒绝任务的处理策略,当线程池没有处理能力的时候,该策略会直接在 execute 方法的调用线程中运行被拒绝的任务;如果执行程序已关闭,则会丢弃该任务
|
||||
ex.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor = ex;
|
||||
}
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package org.dromara.sms4j.starter.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.sms4j.comm.constant.Constant;
|
||||
import org.dromara.sms4j.comm.delayedTime.DelayedTime;
|
||||
import org.dromara.sms4j.provider.config.SmsBanner;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
@ -16,8 +15,6 @@ import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
|
||||
@Data
|
||||
public class SmsMainConfig {
|
||||
@ -33,23 +30,23 @@ public class SmsMainConfig {
|
||||
return BeanFactory.getSmsConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入一个定时器
|
||||
*/
|
||||
@Bean
|
||||
@Lazy
|
||||
protected DelayedTime delayedTime() {
|
||||
return BeanFactory.getDelayedTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注入线程池
|
||||
*/
|
||||
@Bean("smsExecutor")
|
||||
@Lazy
|
||||
protected Executor taskExecutor(SmsConfig config) {
|
||||
return BeanFactory.setExecutor(config);
|
||||
}
|
||||
// /**
|
||||
// * 注入一个定时器
|
||||
// */
|
||||
// @Bean
|
||||
// @Lazy
|
||||
// protected DelayedTime delayedTime() {
|
||||
// return BeanFactory.getDelayedTime();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 注入线程池
|
||||
// */
|
||||
// @Bean("smsExecutor")
|
||||
// @Lazy
|
||||
// protected Executor taskExecutor(SmsConfig config) {
|
||||
// return BeanFactory.setExecutor(config);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 注入一个配置文件读取工具
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user