xuxueli / xxl-job

A distributed task scheduling framework.(分布式任务调度平台XXL-JOB)
http://www.xuxueli.com/xxl-job/
GNU General Public License v3.0
27.45k stars 10.86k forks source link

任务关闭需要提供不同的模式:强制与非强制 #436

Closed guzhangyu closed 6 years ago

guzhangyu commented 6 years ago

Please answer some questions before submitting your issue. Thanks!

Which version of XXL-JOB do you using?

1.9.1

Expected behavior

有些执行中的任务,在执行过程中强制停止会使得数据处于不一致的状态,需要在任务层面增加非强制关闭的选项。在关闭执行器容器的时候,可以停止接收新任务,但是老的正在执行中的任务要等待结束,可以考虑任务层面包含是否能够强制关闭的选项,默认不能。

Actual behavior

所有的任务,停止的时候都是强制通过interrupt关闭,在关闭执行器容器的时候也是通过同样的强制关闭。

Steps to reproduce the behavior

执行器在执行过程中的时候,Kill -15;或者在admin端停止执行。

Other information

xuxueli commented 6 years ago

你好,感谢关注! 任务 “能够强制关闭” 这个属性实用性待探讨,而且会响应后续的阻塞策略,待定。

guzhangyu commented 6 years ago

我指的是执行器关闭的时候,对于运行中的任务是强行杀死的;从代码上看就是如此的。

public void destroy(){
        // destory JobThreadRepository
        if (JobThreadRepository.size() > 0) {
            for (Map.Entry<Integer, JobThread> item: JobThreadRepository.entrySet()) {
                removeJobThread(item.getKey(), "web container destroy and kill the job.");
            }
            JobThreadRepository.clear();
        }

        // destory executor-server
        stopExecutorServer();

        // destory JobLogFileCleanThread
        JobLogFileCleanThread.getInstance().toStop();
    }
public static void removeJobThread(int jobId, String removeOldReason){
        JobThread oldJobThread = JobThreadRepository.remove(jobId);
        if (oldJobThread != null) {
            oldJobThread.toStop(removeOldReason);
            oldJobThread.interrupt();
        }
    }