From 858c6337360b2922b43cbabe2547c47b17beb7c0 Mon Sep 17 00:00:00 2001 From: lepdou Date: Mon, 11 Apr 2022 21:09:11 +0800 Subject: [PATCH 1/2] optimize router example --- .../router-callee-service2/src/main/resources/bootstrap.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud-tencent-examples/polaris-router-example/router-callee-service2/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-router-example/router-callee-service2/src/main/resources/bootstrap.yml index ebf6fe5c8..138c119f6 100644 --- a/spring-cloud-tencent-examples/polaris-router-example/router-callee-service2/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-router-example/router-callee-service2/src/main/resources/bootstrap.yml @@ -7,8 +7,7 @@ spring: tencent: metadata: content: - version: v2 - xx: zz + label1: value2 polaris: address: grpc://127.0.0.1:8091 namespace: default From a4a45c169afc305bbc3d2f66caff79237e168781 Mon Sep 17 00:00:00 2001 From: lepdou Date: Tue, 12 Apr 2022 11:01:13 +0800 Subject: [PATCH 2/2] fix causing cpu 100% when set ScheduledThreadPoolExecutor corePoolSize=0 --- CHANGELOG.md | 1 + .../polaris/registry/PolarisServiceRegistry.java | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b57b739..42b5c9689 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,4 +2,5 @@ --- - [Bugfix: fix router bug and add router example](https://github.com/Tencent/spring-cloud-tencent/pull/89) +- [Bugfix: fix causing cpu 100% when set ScheduledThreadPoolExecutor corePoolSize=0](https://github.com/Tencent/spring-cloud-tencent/pull/98) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java index 7e72a075d..59d65d774 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java @@ -18,8 +18,8 @@ package com.tencent.cloud.polaris.registry; +import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import com.tencent.cloud.common.metadata.config.MetadataLocalProperties; @@ -71,13 +71,11 @@ public class PolarisServiceRegistry implements ServiceRegistry { this.polarisDiscoveryProperties = polarisDiscoveryProperties; this.polarisDiscoveryHandler = polarisDiscoveryHandler; this.metadataLocalProperties = metadataLocalProperties; + if (polarisDiscoveryProperties.isHeartbeatEnabled()) { - ScheduledThreadPoolExecutor heartbeatExecutor = new ScheduledThreadPoolExecutor( - 0, new NamedThreadFactory("spring-cloud-heartbeat")); - heartbeatExecutor.setMaximumPoolSize(1); - this.heartbeatExecutor = heartbeatExecutor; - } - else { + this.heartbeatExecutor = Executors + .newSingleThreadScheduledExecutor(new NamedThreadFactory("spring-cloud-heartbeat")); + } else { this.heartbeatExecutor = null; } }