diff --git a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/JSONUtil.java b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/JSONUtil.java index a4392891..fd6d9131 100644 --- a/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/JSONUtil.java +++ b/hippo4j-common/src/main/java/cn/hippo4j/common/toolkit/JSONUtil.java @@ -20,6 +20,7 @@ package cn.hippo4j.common.toolkit; import cn.hippo4j.common.api.JsonFacade; import com.fasterxml.jackson.core.type.TypeReference; +import java.util.Collections; import java.util.List; /** @@ -52,7 +53,7 @@ public class JSONUtil { public static List parseArray(String text, Class clazz) { if (StringUtil.isBlank(text)) { - return null; + return Collections.emptyList(); } return JSON_FACADE.parseArray(text, clazz); } diff --git a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/JSONUtilTest.java b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/JSONUtilTest.java index 1bb988d0..e01ff4cd 100644 --- a/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/JSONUtilTest.java +++ b/hippo4j-common/src/test/java/cn/hippo4j/common/toolkit/JSONUtilTest.java @@ -26,6 +26,7 @@ import org.junit.Assert; import org.junit.Test; import java.util.Arrays; +import java.util.Collections; import java.util.List; public class JSONUtilTest { @@ -65,8 +66,8 @@ public class JSONUtilTest { @Test public void assertParseArray() { - Assert.assertNull(JSONUtil.parseArray(null, Foo.class)); - Assert.assertNull(JSONUtil.parseArray(" ", Foo.class)); + Assert.assertEquals(Collections.emptyList(), JSONUtil.parseArray(null, Foo.class)); + Assert.assertEquals(Collections.emptyList(), JSONUtil.parseArray(" ", Foo.class)); Assert.assertEquals( EXPECTED_FOO_ARRAY, JSONUtil.parseArray(EXPECTED_FOO_JSON_ARRAY, Foo.class)); diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java index a8827549..a99b0b37 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolWrapper.java @@ -51,6 +51,7 @@ public class DynamicThreadPoolWrapper implements DisposableBean { public DynamicThreadPoolWrapper(String threadPoolId, ThreadPoolExecutor threadPoolExecutor) { this.threadPoolId = threadPoolId; this.executor = threadPoolExecutor; + this.subscribeFlag = true; } public void execute(Runnable command) { @@ -67,7 +68,7 @@ public class DynamicThreadPoolWrapper implements DisposableBean { @Override public void destroy() throws Exception { - if (executor != null && executor instanceof AbstractDynamicExecutorSupport) { + if (executor instanceof AbstractDynamicExecutorSupport) { ((AbstractDynamicExecutorSupport) executor).destroy(); } } diff --git a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java index 04190dd0..c426f3ad 100644 --- a/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-config-spring-boot-starter/src/main/java/cn/hippo4j/config/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -204,17 +204,17 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { private ThreadPoolNotifyAlarm buildThreadPoolNotifyAlarm(ExecutorProperties executorProperties) { DynamicThreadPoolNotifyProperties notify = Optional.ofNullable(executorProperties).map(ExecutorProperties::getNotify).orElse(null); boolean isAlarm = Optional.ofNullable(executorProperties.getAlarm()) - .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getAlarm()).orElse(true)); + .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getAlarm).orElse(true)); int activeAlarm = Optional.ofNullable(executorProperties.getActiveAlarm()) - .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getActiveAlarm()).orElse(80)); + .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getActiveAlarm).orElse(80)); int capacityAlarm = Optional.ofNullable(executorProperties.getCapacityAlarm()) - .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getCapacityAlarm()).orElse(80)); + .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getCapacityAlarm).orElse(80)); int interval = Optional.ofNullable(notify) - .map(each -> each.getInterval()) - .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getNotify()).map(each -> each.getInterval()).orElse(5)); + .map(DynamicThreadPoolNotifyProperties::getInterval) + .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getNotify).map(DynamicThreadPoolNotifyProperties::getInterval).orElse(5)); String receive = Optional.ofNullable(notify) - .map(each -> each.getReceives()) - .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getNotify()).map(each -> each.getReceives()).orElse("")); + .map(DynamicThreadPoolNotifyProperties::getReceives) + .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getNotify).map(DynamicThreadPoolNotifyProperties::getReceives).orElse("")); ThreadPoolNotifyAlarm threadPoolNotifyAlarm = new ThreadPoolNotifyAlarm(isAlarm, activeAlarm, capacityAlarm); threadPoolNotifyAlarm.setInterval(interval); threadPoolNotifyAlarm.setReceives(receive); diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/DynamicThreadPoolSubscribeConfig.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/DynamicThreadPoolSubscribeConfig.java index 6e57b6f4..5a087427 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/DynamicThreadPoolSubscribeConfig.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/core/DynamicThreadPoolSubscribeConfig.java @@ -53,7 +53,7 @@ public class DynamicThreadPoolSubscribeConfig { .build(); public void subscribeConfig(String threadPoolId) { - subscribeConfig(threadPoolId, config -> threadPoolDynamicRefresh.dynamicRefresh(config)); + subscribeConfig(threadPoolId, threadPoolDynamicRefresh::dynamicRefresh); } public void subscribeConfig(String threadPoolId, ThreadPoolSubscribeCallback threadPoolSubscribeCallback) { diff --git a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java index 80d147c5..e75fab27 100644 --- a/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -130,7 +130,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { queryStrMap.put(TP_ID, threadPoolId); queryStrMap.put(ITEM_ID, properties.getItemId()); queryStrMap.put(NAMESPACE, properties.getNamespace()); - boolean isSubscribe = false; ThreadPoolExecutor newDynamicThreadPoolExecutor = null; ThreadPoolParameterInfo threadPoolParameterInfo = new ThreadPoolParameterInfo(); try { @@ -167,7 +166,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { ((DynamicThreadPoolExecutor) newDynamicThreadPoolExecutor).setExecuteTimeOut(executeTimeOut); } dynamicThreadPoolWrapper.setExecutor(newDynamicThreadPoolExecutor); - isSubscribe = true; } } else { // DynamicThreadPool configuration undefined in server @@ -197,8 +195,6 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { if (Objects.isNull(executor)) { dynamicThreadPoolWrapper.setExecutor(CommonDynamicThreadPool.getInstance(threadPoolId)); } - // Set whether to subscribe to the remote thread pool configuration. - dynamicThreadPoolWrapper.setSubscribeFlag(isSubscribe); } GlobalThreadPoolManage.register(dynamicThreadPoolWrapper.getThreadPoolId(), threadPoolParameterInfo, dynamicThreadPoolWrapper); return newDynamicThreadPoolExecutor;