From 4e8e049a7b8b179376caf7d26940b6bbc83b983b Mon Sep 17 00:00:00 2001 From: WEIZIBIN Date: Thu, 29 Aug 2019 23:54:11 +0800 Subject: [PATCH] waitting for running thread shutdown before callback thread toStop --- .../com/xxl/job/core/executor/XxlJobExecutor.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java index e617becc..1823ee81 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java @@ -86,6 +86,11 @@ public class XxlJobExecutor { initRpcProvider(ip, port, appName, accessToken); } public void destroy(){ + List runningThreads = new ArrayList<>(jobThreadRepository.values()); + if (logger.isInfoEnabled()) { + logger.info("running threads {}", runningThreads); + } + // destory jobThreadRepository if (jobThreadRepository.size() > 0) { for (Map.Entry item: jobThreadRepository.entrySet()) { @@ -95,6 +100,15 @@ public class XxlJobExecutor { } jobHandlerRepository.clear(); + for (JobThread runningThread : runningThreads) { + try { + // wait for all job thread push result to callback queue + runningThread.join(); + } catch (InterruptedException e) { + logger.warn("interrupted while stopping {}", runningThread); + break; + } + } // destory JobLogFileCleanThread JobLogFileCleanThread.getInstance().toStop();