1

我有一份工作在每天的特定时间运行。我必须使用一些逻辑更新作业的 CronExpression,问题是一旦 CronExpression 更新,我必须重新启动服务器以使用新时间运行该作业。如何在不重新启动服务器的情况下重新启动作业。我已经搜索了其他问题,但找不到我的解决方案。

我为另一项工作更新 cronExpression 的工作是:

public void reSchedulerNotofocationjob(){
        List<Slots> slots=config.getActiveConfiguration().getSlotDetils();
        int size=slots.size();
        LocalTime slotTime;
        LocalTime currenttime=new LocalTime();
        String cronExp;
        BatchJobs batchJobs= mongoOperations.findById("5b1f69c21f74e5ecc0c607ea", BatchJobs.class);
        logger.debug("batch job id and job name "+batchJobs.getId()+" and "+batchJobs.getJobName());

        for(int i=0; i<size;i++){
            slotTime= LocalTime.parse(slots.get(i).getSlotTime());
            if(currenttime.isBefore(slotTime)){
                cronExp=slotTime.getSecondOfMinute()+" "+slotTime.getMinuteOfHour()+" "+slotTime.getHourOfDay()+" * * ? *";
                mongoOperations.findAndModify(new Query(Criteria.where("_id").is("5b1f69c21f74e5ecc0c607ea")), new Update().set("cronExpression", cronExp), BatchJobs.class);
                break;
            }else{
                if(i+1<size){
                    slotTime= LocalTime.parse(slots.get(i+1).getSlotTime());
                    if(currenttime.isBefore(slotTime)){
                        cronExp=slotTime.getSecondOfMinute()+" "+slotTime.getMinuteOfHour()+" "+slotTime.getHourOfDay()+" * * ? *";
                        mongoOperations.findAndModify(new Query(Criteria.where("_id").is("5b1f69c21f74e5ecc0c607ea")), new Update().set("cronExpression", cronExp), BatchJobs.class);
                        break;
                    }
                }else{
                    slotTime= LocalTime.parse(slots.get(0).getSlotTime());
                    cronExp=slotTime.getSecondOfMinute()+" "+slotTime.getMinuteOfHour()+" "+slotTime.getHourOfDay()+" * * ? *";
                    mongoOperations.findAndModify(new Query(Criteria.where("_id").is("5b1f69c21f74e5ecc0c607ea")), new Update().set("cronExpression", cronExp), BatchJobs.class);
                    break;
                }
            }
        }

    }

如何重新启动批处理作业..

4

0 回答 0