|
@@ -84,33 +84,26 @@ public class XxlJobExecutor {
|
|
|
initRpcProvider(ip, port, appName, accessToken);
|
|
|
}
|
|
|
public void destroy(){
|
|
|
-
|
|
|
- List<JobThread> runningThreads = new ArrayList<>(jobThreadRepository.values());
|
|
|
- if (logger.isInfoEnabled()) {
|
|
|
- logger.info("running threads {}", runningThreads);
|
|
|
- }
|
|
|
-
|
|
|
// destory executor-server
|
|
|
stopRpcProvider();
|
|
|
|
|
|
// destory jobThreadRepository
|
|
|
if (jobThreadRepository.size() > 0) {
|
|
|
for (Map.Entry<Integer, JobThread> item: jobThreadRepository.entrySet()) {
|
|
|
- removeJobThread(item.getKey(), "web container destroy and kill the job.");
|
|
|
+ JobThread oldJobThread = removeJobThread(item.getKey(), "web container destroy and kill the job.");
|
|
|
+ // wait for job thread push result to callback queue
|
|
|
+ if (oldJobThread != null) {
|
|
|
+ try {
|
|
|
+ oldJobThread.join();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ logger.error(">>>>>>>>>>> xxl-job, JobThread destroy(join) error, jobId:{}", item.getKey(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
jobThreadRepository.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
|
|
|
JobLogFileCleanThread.getInstance().toStop();
|
|
@@ -246,12 +239,15 @@ public class XxlJobExecutor {
|
|
|
|
|
|
return newJobThread;
|
|
|
}
|
|
|
- public static void removeJobThread(int jobId, String removeOldReason){
|
|
|
+ public static JobThread removeJobThread(int jobId, String removeOldReason){
|
|
|
JobThread oldJobThread = jobThreadRepository.remove(jobId);
|
|
|
if (oldJobThread != null) {
|
|
|
oldJobThread.toStop(removeOldReason);
|
|
|
oldJobThread.interrupt();
|
|
|
+
|
|
|
+ return oldJobThread;
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
public static JobThread loadJobThread(int jobId){
|
|
|
JobThread jobThread = jobThreadRepository.get(jobId);
|