waitting for running thread shutdown before callback thread toStop

This commit is contained in:
WEIZIBIN 2019-08-29 23:54:11 +08:00
parent 59f68132ea
commit 4e8e049a7b
1 changed files with 14 additions and 0 deletions

View File

@ -86,6 +86,11 @@ public class XxlJobExecutor {
initRpcProvider(ip, port, appName, accessToken); initRpcProvider(ip, port, appName, accessToken);
} }
public void destroy(){ public void destroy(){
List<JobThread> runningThreads = new ArrayList<>(jobThreadRepository.values());
if (logger.isInfoEnabled()) {
logger.info("running threads {}", runningThreads);
}
// destory jobThreadRepository // destory jobThreadRepository
if (jobThreadRepository.size() > 0) { if (jobThreadRepository.size() > 0) {
for (Map.Entry<Integer, JobThread> item: jobThreadRepository.entrySet()) { for (Map.Entry<Integer, JobThread> item: jobThreadRepository.entrySet()) {
@ -95,6 +100,15 @@ public class XxlJobExecutor {
} }
jobHandlerRepository.clear(); 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 // destory JobLogFileCleanThread
JobLogFileCleanThread.getInstance().toStop(); JobLogFileCleanThread.getInstance().toStop();