Skip to content

Commit a69e297

Browse files
skaiclinghengqian
authored andcommitted
wait all process stop
1 parent e0e2cba commit a69e297

File tree

1 file changed

+12
-1
lines changed
  • elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor

1 file changed

+12
-1
lines changed

elasticjob-ecosystem/elasticjob-executor/elasticjob-executor-kernel/src/main/java/org/apache/shardingsphere/elasticjob/executor/ElasticJobExecutor.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Queue;
3939
import java.util.concurrent.CancellationException;
4040
import java.util.concurrent.ConcurrentHashMap;
41+
import java.util.concurrent.CountDownLatch;
4142
import java.util.concurrent.ExecutionException;
4243
import java.util.concurrent.ExecutorService;
4344
import java.util.concurrent.Future;
@@ -141,14 +142,19 @@ private void execute(final JobConfiguration jobConfig, final ShardingContexts sh
141142
private void process(final JobConfiguration jobConfig, final ShardingContexts shardingContexts, final ExecutionSource executionSource) {
142143
Collection<Integer> items = shardingContexts.getShardingItemParameters().keySet();
143144
Queue<Future<Boolean>> futures = new LinkedList<>();
145+
CountDownLatch latch = new CountDownLatch(items.size());
144146
for (int each : items) {
145147
JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(IpUtils.getHostName(), IpUtils.getIp(), shardingContexts.getTaskId(), jobConfig.getJobName(), executionSource, each);
146148
ExecutorService executorService = executorContext.get(ExecutorService.class);
147149
if (executorService.isShutdown()) {
148150
return;
149151
}
150152
Future<Boolean> future = executorService.submit(() -> {
151-
process(jobConfig, shardingContexts, each, jobExecutionEvent);
153+
try {
154+
process(jobConfig, shardingContexts, each, jobExecutionEvent);
155+
} finally {
156+
latch.countDown();
157+
}
152158
return true;
153159
});
154160
futures.offer(future);
@@ -179,7 +185,12 @@ private void process(final JobConfiguration jobConfig, final ShardingContexts sh
179185
} finally {
180186
futures.poll();
181187
}
188+
}
182189

190+
try {
191+
latch.await();
192+
} catch (final InterruptedException ex) {
193+
Thread.currentThread().interrupt();
183194
}
184195
}
185196

0 commit comments

Comments
 (0)