diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b0cfbea..9671d48dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,4 @@ - [Test:support environment variable metadata test](https://github.com/Tencent/spring-cloud-tencent/pull/710) - [upgrade protobuf-java.version to 3.21.7](https://github.com/Tencent/spring-cloud-tencent/pull/716) - [docs:update README.](https://github.com/Tencent/spring-cloud-tencent/pull/719) +- [Code optimization & correct comment](https://github.com/Tencent/spring-cloud-tencent/pull/723) diff --git a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java index 3736a45d3..a245d695a 100644 --- a/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-circuitbreaker/src/main/java/com/tencent/cloud/polaris/circuitbreaker/config/PolarisCircuitBreakerAutoConfiguration.java @@ -59,7 +59,7 @@ public class PolarisCircuitBreakerAutoConfiguration { // Turn on circuitbreaker configuration configuration.getConsumer().getCircuitBreaker().setEnable(true); - // Set excludeCircuitBreakInstances to false + // Set excludeCircuitBreakInstances to true RecoverRouterConfig recoverRouterConfig = configuration.getConsumer().getServiceRouter() .getPluginConfig(ServiceRouterConfig.DEFAULT_ROUTER_RECOVER, RecoverRouterConfig.class); diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueRegistry.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueRegistry.java index 473ed909e..9e2c2657d 100644 --- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueRegistry.java +++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/property/SpringValueRegistry.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -33,6 +34,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.DisposableBean; /** * Spring value auto registry. @@ -43,13 +45,14 @@ import org.springframework.beans.factory.BeanFactory; * * @author weihubeats 2022-7-10 */ -public class SpringValueRegistry { +public class SpringValueRegistry implements DisposableBean { private static final Logger logger = LoggerFactory.getLogger(SpringValueRegistry.class); private static final long CLEAN_INTERVAL_IN_SECONDS = 5; private final Map> registry = Maps.newConcurrentMap(); private final AtomicBoolean initialized = new AtomicBoolean(false); private final Object LOCK = new Object(); + private ScheduledExecutorService executor; public void register(BeanFactory beanFactory, String key, SpringValue springValue) { if (!registry.containsKey(beanFactory)) { @@ -77,8 +80,9 @@ public class SpringValueRegistry { } private void initialize() { - Executors.newSingleThreadScheduledExecutor( - new NamedThreadFactory("polaris-spring-value-registry")).scheduleAtFixedRate( + executor = Executors.newSingleThreadScheduledExecutor( + new NamedThreadFactory("polaris-spring-value-registry")); + executor.scheduleAtFixedRate( () -> { try { scanAndClean(); @@ -97,4 +101,9 @@ public class SpringValueRegistry { springValues.entries().removeIf(springValue -> !springValue.getValue().isTargetBeanValid()); } } + + @Override + public void destroy() throws Exception { + executor.shutdown(); + } } diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/scg/PolarisReactiveLoadBalancerClientFilter.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/scg/PolarisReactiveLoadBalancerClientFilter.java index 1fd3e2186..0c0f30875 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/scg/PolarisReactiveLoadBalancerClientFilter.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/scg/PolarisReactiveLoadBalancerClientFilter.java @@ -184,6 +184,7 @@ public class PolarisReactiveLoadBalancerClientFilter extends ReactiveLoadBalance new ResponseData(exchange.getResponse(), new RequestData(exchange.getRequest())))))); } + @Override protected URI reconstructURI(ServiceInstance serviceInstance, URI original) { return LoadBalancerUriTools.reconstructURI(serviceInstance, original); }