This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 9be24e4  Refactor thread factory in SchemaBuilder (#10546)
9be24e4 is described below

commit 9be24e4d28b57659277f567a7ce6940597b66f9b
Author: 吴伟杰 <[email protected]>
AuthorDate: Sat May 29 22:27:28 2021 +0800

    Refactor thread factory in SchemaBuilder (#10546)
---
 .../infra/metadata/schema/builder/SchemaBuilder.java    | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
index bda0f60..41d218c 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/schema/builder/SchemaBuilder.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.infra.metadata.schema.builder;
 
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
@@ -47,10 +48,8 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
 import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -60,7 +59,7 @@ import java.util.stream.Collectors;
 public final class SchemaBuilder {
     
     private static final ExecutorService EXECUTOR_SERVICE = new 
ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2, 
Runtime.getRuntime().availableProcessors() * 2,
-            0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new 
SchemaBuilderThreadFactory());
+            0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new 
ThreadFactoryBuilder().setDaemon(true).setNameFormat("ShardingSphere-SchemaBuilder-%d").build());
     
     static {
         ShardingSphereServiceLoader.register(DialectTableMetaDataLoader.class);
@@ -161,16 +160,4 @@ public final class SchemaBuilder {
         result.addAll(schema.getAllTableNames());
         return result;
     }
-    
-    private static class SchemaBuilderThreadFactory implements ThreadFactory {
-        
-        private final AtomicInteger threadSequence = new AtomicInteger(0);
-    
-        @Override
-        public Thread newThread(final Runnable runnable) {
-            Thread result = new Thread(runnable, 
String.format("SchemaBuilderExecutor-%d", threadSequence.getAndIncrement()));
-            result.setDaemon(true);
-            return result;
-        }
-    }
 }

Reply via email to