You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/08/17 09:49:57 UTC
[servicecomb-java-chassis] branch 1.3.x updated: [SCB-1710] catch
the throwable from the scheduled pulling task (#2509)
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch 1.3.x
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/1.3.x by this push:
new 6be61e3 [SCB-1710] catch the throwable from the scheduled pulling task (#2509)
6be61e3 is described below
commit 6be61e31da3936d2eb58783a6988549ee96af176
Author: david6969xin <86...@users.noreply.github.com>
AuthorDate: Tue Aug 17 17:49:50 2021 +0800
[SCB-1710] catch the throwable from the scheduled pulling task (#2509)
* [SCB-1710] catch the throwable from the scheduled pulling task
* [SCB-1710] catch the throwable from the scheduled pulling task
* [SCB-1710] catch the throwable from the scheduled pulling task
---
.../registry/RemoteServiceRegistry.java | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
index eed2d08..0a8689f 100644
--- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
+++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
@@ -18,6 +18,7 @@ package org.apache.servicecomb.serviceregistry.registry;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
@@ -53,18 +54,15 @@ public class RemoteServiceRegistry extends AbstractServiceRegistry {
public void init() {
super.init();
taskPool = new ScheduledThreadPoolExecutor(3,
- task -> {
- return new Thread(task) {
- @Override
- public void run() {
- try {
- setName("Service Center Task [" + task.toString() + "[" + this.getId() + "]]");
- super.run();
- } catch (Throwable e) {
- LOGGER.error("task {} execute error.", getName(), e);
- }
- }
- };
+ new ThreadFactory() {
+ private int taskId = 0;
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(r, "Service Center Task [" + (taskId++) + "]");
+ thread.setUncaughtExceptionHandler(
+ (t, e) -> LOGGER.error("Service Center Task Thread is terminated! thread: [{}]", t, e));
+ return thread;
+ }
},
(task, executor) -> LOGGER.warn("Too many pending tasks, reject " + task.toString())
);