代码优化.

pull/142/head
chen.ma 2 years ago
parent 8ede173bbb
commit cb842fa083

@ -1,12 +0,0 @@
package cn.hippo4j.core.config;
/**
* Thread pool notify alarm config.
*
* @author chen.ma
* @date 2022/3/3 20:45
*/
public class ThreadPoolNotifyAlarmConfig {
}

@ -17,12 +17,12 @@ import java.util.concurrent.ConcurrentHashMap;
public class GlobalThreadPoolManage {
/**
* 线
* 线.
*/
private static final Map<String, PoolParameter> POOL_PARAMETER = new ConcurrentHashMap();
/**
* 线
* 线.
*/
private static final Map<String, DynamicThreadPoolWrapper> EXECUTOR_MAP = new ConcurrentHashMap();

@ -5,7 +5,7 @@ package cn.hippo4j.core.starter.parser;
* @date : 2022/3/1 07:50
* @description:
*/
public abstract class AbstractConfigParser implements ConfigParser{
public abstract class AbstractConfigParser implements ConfigParser {
@Override
public boolean supports(ConfigFileTypeEnum type) {

@ -11,10 +11,28 @@ import java.util.Map;
*/
public interface ConfigParser {
/**
* Supports.
*
* @param type
* @return
*/
boolean supports(ConfigFileTypeEnum type);
/**
* Do parse.
*
* @param content
* @return
* @throws IOException
*/
Map<Object, Object> doParse(String content) throws IOException;
/**
* Get config file types.
*
* @return
*/
List<ConfigFileTypeEnum> getConfigFileTypes();
}

@ -33,6 +33,7 @@ public class ConfigParserHandler {
return parser.doParse(content);
}
}
return Collections.emptyMap();
}

@ -13,8 +13,7 @@ import java.util.Properties;
* @date : 2022/3/1 07:49
* @description:
*/
public class PropertiesConfigParser extends AbstractConfigParser{
public class PropertiesConfigParser extends AbstractConfigParser {
@Override
public Map<Object, Object> doParse(String content) throws IOException {
@ -27,4 +26,5 @@ public class PropertiesConfigParser extends AbstractConfigParser{
public List<ConfigFileTypeEnum> getConfigFileTypes() {
return Lists.newArrayList(ConfigFileTypeEnum.PROPERTIES);
}
}

@ -21,8 +21,10 @@ public class YamlConfigParser extends AbstractConfigParser {
if (StringUtils.isEmpty(content)) {
return Maps.newHashMapWithExpectedSize(0);
}
YamlPropertiesFactoryBean bean = new YamlPropertiesFactoryBean();
bean.setResources(new ByteArrayResource(content.getBytes()));
return bean.getObject();
}
@ -30,4 +32,5 @@ public class YamlConfigParser extends AbstractConfigParser {
public List<ConfigFileTypeEnum> getConfigFileTypes() {
return Lists.newArrayList(ConfigFileTypeEnum.YML, ConfigFileTypeEnum.YAML);
}
}

@ -59,6 +59,7 @@ public class BootstrapCorePropertiesBinderAdapt {
* @param configInfo
* @return
*/
@Deprecated
private static BootstrapCoreProperties adapt(Map<Object, Object> configInfo) {
BootstrapCoreProperties bindableCoreProperties;
try {

@ -2,6 +2,7 @@ package cn.hippo4j.core.starter.support;
import cn.hippo4j.common.config.ApplicationContextHolder;
import cn.hippo4j.common.notify.ThreadPoolNotifyAlarm;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
@ -99,10 +100,11 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
try {
// 使用相关参数创建线程池
BlockingQueue workQueue = QueueTypeEnum.createBlockingQueue(executorProperties.getBlockingQueue(), executorProperties.getQueueCapacity());
String threadNamePrefix = executorProperties.getThreadNamePrefix();
newDynamicPoolExecutor = ThreadPoolBuilder.builder()
.dynamicPool()
.workQueue(workQueue)
.threadFactory(threadPoolId)
.threadFactory(StringUtil.isNotBlank(threadNamePrefix) ? threadNamePrefix : threadPoolId)
.executeTimeOut(Optional.ofNullable(executorProperties.getExecuteTimeOut()).orElse(0L))
.poolThreadSize(executorProperties.getCorePoolSize(), executorProperties.getMaximumPoolSize())
.keepAliveTime(executorProperties.getKeepAliveTime(), TimeUnit.SECONDS)

Loading…
Cancel
Save