You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/08/02 15:14:26 UTC

[shardingsphere-elasticjob] branch master updated: ElasticJobExecutor create executorService as job executed (#1315) (#1316)

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-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new adb2131  ElasticJobExecutor create executorService as job executed (#1315) (#1316)
adb2131 is described below

commit adb213163e6580c053df5d4d8c93539a5e5f66d3
Author: Tboy <gu...@immomo.com>
AuthorDate: Sun Aug 2 23:14:18 2020 +0800

    ElasticJobExecutor create executorService as job executed (#1315) (#1316)
---
 .../elasticjob/executor/ElasticJobExecutor.java    |  9 ++++++--
 .../lite/internal/schedule/JobScheduler.java       | 27 ++++++++++------------
 .../elasticjob/lite/internal/schedule/LiteJob.java | 16 ++-----------
 3 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java b/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
index 45b0f54..a21428e 100644
--- a/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
+++ b/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java
@@ -113,8 +113,6 @@ public final class ElasticJobExecutor {
         } catch (final Throwable cause) {
             //CHECKSTYLE:ON
             jobErrorHandler.handleException(jobConfig.getJobName(), cause);
-        } finally {
-            executorService.shutdown();
         }
     }
     
@@ -187,4 +185,11 @@ public final class ElasticJobExecutor {
             jobErrorHandler.handleException(jobConfig.getJobName(), cause);
         }
     }
+    
+    /**
+     * Shutdown executor.
+     */
+    public void shutdown() {
+        executorService.shutdown();
+    }
 }
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
index 7064048..559cfaf 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/JobScheduler.java
@@ -21,6 +21,7 @@ import lombok.Getter;
 import org.apache.shardingsphere.elasticjob.api.ElasticJob;
 import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.api.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.executor.ElasticJobExecutor;
 import org.apache.shardingsphere.elasticjob.infra.exception.JobSystemException;
 import org.apache.shardingsphere.elasticjob.infra.handler.sharding.JobInstance;
 import org.apache.shardingsphere.elasticjob.lite.api.listener.AbstractDistributeOnceElasticJobListener;
@@ -45,13 +46,7 @@ import java.util.Properties;
  */
 public final class JobScheduler {
     
-    private static final String ELASTIC_JOB_DATA_MAP_KEY = "elasticJob";
-    
-    private static final String ELASTIC_JOB_TYPE_DATA_MAP_KEY = "elasticJobType";
-    
-    private static final String JOB_CONFIG_DATA_MAP_KEY = "jobConfig";
-    
-    private static final String JOB_FACADE_DATA_MAP_KEY = "jobFacade";
+    private static final String JOB_EXECUTOR_DATA_MAP_KEY = "jobExecutor";
     
     private final CoordinatorRegistryCenter regCenter;
     
@@ -64,12 +59,14 @@ public final class JobScheduler {
     
     private final List<ElasticJobListener> elasticJobListeners;
     
-    private final TracingConfiguration<?> tracingConfig;
-    
     private final SetUpFacade setUpFacade;
     
     private final SchedulerFacade schedulerFacade;
     
+    private final LiteJobFacade jobFacade;
+    
+    private final ElasticJobExecutor jobExecutor;
+    
     @Getter
     private final JobScheduleController jobScheduleController;
     
@@ -83,9 +80,10 @@ public final class JobScheduler {
         this.elasticJob = elasticJob;
         elasticJobType = null;
         this.elasticJobListeners = Arrays.asList(elasticJobListeners);
-        this.tracingConfig = tracingConfig;
         setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), this.elasticJobListeners);
         schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
+        jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), this.elasticJobListeners, tracingConfig);
+        jobExecutor = null == elasticJob ? new ElasticJobExecutor(elasticJobType, jobConfig, jobFacade) : new ElasticJobExecutor(elasticJob, jobConfig, jobFacade);
         String jobClassName = JobClassNameProviderFactory.getProvider().getJobClassName(elasticJob);
         this.jobConfig = setUpFacade.setUpJobConfiguration(jobClassName, jobConfig);
         setGuaranteeServiceForElasticJobListeners(regCenter, this.elasticJobListeners);
@@ -102,9 +100,10 @@ public final class JobScheduler {
         elasticJob = null;
         this.elasticJobType = elasticJobType;
         this.elasticJobListeners = Arrays.asList(elasticJobListeners);
-        this.tracingConfig = tracingConfig;
         setUpFacade = new SetUpFacade(regCenter, jobConfig.getJobName(), this.elasticJobListeners);
         schedulerFacade = new SchedulerFacade(regCenter, jobConfig.getJobName());
+        jobFacade = new LiteJobFacade(regCenter, jobConfig.getJobName(), this.elasticJobListeners, tracingConfig);
+        jobExecutor = null == elasticJob ? new ElasticJobExecutor(elasticJobType, jobConfig, jobFacade) : new ElasticJobExecutor(elasticJob, jobConfig, jobFacade);
         this.jobConfig = setUpFacade.setUpJobConfiguration(elasticJobType, jobConfig);
         setGuaranteeServiceForElasticJobListeners(regCenter, this.elasticJobListeners);
         jobScheduleController = createJobScheduleController();
@@ -152,10 +151,7 @@ public final class JobScheduler {
     
     private JobDetail createJobDetail() {
         JobDetail result = JobBuilder.newJob(LiteJob.class).withIdentity(getJobConfig().getJobName()).build();
-        result.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJob);
-        result.getJobDataMap().put(ELASTIC_JOB_TYPE_DATA_MAP_KEY, elasticJobType);
-        result.getJobDataMap().put(JOB_CONFIG_DATA_MAP_KEY, getJobConfig());
-        result.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, new LiteJobFacade(regCenter, jobConfig.getJobName(), elasticJobListeners, tracingConfig));
+        result.getJobDataMap().put(JOB_EXECUTOR_DATA_MAP_KEY, jobExecutor);
         return result;
     }
     
@@ -171,5 +167,6 @@ public final class JobScheduler {
     */
     public void shutdown() {
         schedulerFacade.shutdownInstance();
+        jobExecutor.shutdown();
     }
 }
diff --git a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJob.java b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJob.java
index 216277a..4b786f8 100644
--- a/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJob.java
+++ b/elasticjob-lite/elasticjob-lite-core/src/main/java/org/apache/shardingsphere/elasticjob/lite/internal/schedule/LiteJob.java
@@ -18,10 +18,7 @@
 package org.apache.shardingsphere.elasticjob.lite.internal.schedule;
 
 import lombok.Setter;
-import org.apache.shardingsphere.elasticjob.api.ElasticJob;
-import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
 import org.apache.shardingsphere.elasticjob.executor.ElasticJobExecutor;
-import org.apache.shardingsphere.elasticjob.executor.JobFacade;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 
@@ -31,20 +28,11 @@ import org.quartz.JobExecutionContext;
 @Setter
 public final class LiteJob implements Job {
     
-    private ElasticJob elasticJob;
-    
-    private String elasticJobType;
-    
-    private JobConfiguration jobConfig;
-    
-    private JobFacade jobFacade;
+    private ElasticJobExecutor jobExecutor;
     
     @Override
     public void execute(final JobExecutionContext context) {
-        createExecutor().execute();
+        jobExecutor.execute();
     }
     
-    private ElasticJobExecutor createExecutor() {
-        return null == elasticJob ? new ElasticJobExecutor(elasticJobType, jobConfig, jobFacade) : new ElasticJobExecutor(elasticJob, jobConfig, jobFacade);
-    }
 }