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

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


The following commit(s) were added to refs/heads/master by this push:
     new 06ed9cf  static ExecutorService in JobTracingEventBus (#1935)
06ed9cf is described below

commit 06ed9cf8b0ac295c85db55f7b37869b5b294c7c3
Author: skai <[email protected]>
AuthorDate: Tue Jul 20 22:27:50 2021 +0800

    static ExecutorService in JobTracingEventBus (#1935)
    
    Co-authored-by: 蔡顺铠 <[email protected]>
---
 .../elasticjob/tracing/JobTracingEventBus.java           | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git 
a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/JobTracingEventBus.java
 
b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/JobTracingEventBus.java
index 50a18cc..46df6e4 100644
--- 
a/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/JobTracingEventBus.java
+++ 
b/elasticjob-ecosystem/elasticjob-tracing/elasticjob-tracing-api/src/main/java/org/apache/shardingsphere/elasticjob/tracing/JobTracingEventBus.java
@@ -37,25 +37,27 @@ import java.util.concurrent.TimeUnit;
  */
 @Slf4j
 public final class JobTracingEventBus {
-    
-    private final ExecutorService executorService;
+
+    private static final ExecutorService EXECUTOR_SERVICE;
     
     private final EventBus eventBus;
     
     private volatile boolean isRegistered;
+
+    static {
+        EXECUTOR_SERVICE = 
createExecutorService(Runtime.getRuntime().availableProcessors() * 2);
+    }
     
     public JobTracingEventBus() {
-        executorService = null;
         eventBus = null;
     }
     
     public JobTracingEventBus(final TracingConfiguration<?> tracingConfig) {
-        executorService = 
createExecutorService(Runtime.getRuntime().availableProcessors() * 2);
-        eventBus = new AsyncEventBus(executorService);
+        eventBus = new AsyncEventBus(EXECUTOR_SERVICE);
         register(tracingConfig);
     }
     
-    private ExecutorService createExecutorService(final int threadSize) {
+    private static ExecutorService createExecutorService(final int threadSize) 
{
         ThreadPoolExecutor threadPoolExecutor = new 
ThreadPoolExecutor(threadSize, threadSize, 5L, TimeUnit.MINUTES, 
                 new LinkedBlockingQueue<>(), new 
BasicThreadFactory.Builder().namingPattern(String.join("-", "job-event", 
"%s")).build());
         threadPoolExecutor.allowCoreThreadTimeOut(true);
@@ -77,7 +79,7 @@ public final class JobTracingEventBus {
      * @param event job event
      */
     public void post(final JobEvent event) {
-        if (isRegistered && !executorService.isShutdown()) {
+        if (isRegistered && !EXECUTOR_SERVICE.isShutdown()) {
             eventBus.post(event);
         }
     }

Reply via email to