如何立即或有力地停止春季批处理作业执行?

发布于 2025-02-12 05:57:37 字数 1631 浏览 0 评论 0原文

我有一个春季批处理作业,它有3个步骤,第三步有以下任务。现在,当我们尝试停止使用工作时,

jobOperator.stop(id);

它会在步骤3进行进行时发送停止信号,并且仅当步骤3中的所有任务完成时才中断。假设它有10个任务,尽管我们在步骤3和正在进行的任务1时发送了停止信号 - 它不止于此。它完成了所有10个任务,然后标记已完成的步骤3状态。有什么办法可以在处理第一个任务时停止步骤3?我确实看到了春季批处理文档,但找不到太多。以下是示例代码。

作业:

   @Bean(JobConstants.CONTENT_UPGRADE_JOB)
    public Job upgradeContentJob() {
        Tasklet tasklet = context.getBean("incremental_deploy_tasklet", Tasklet.class);
        SimpleJobBuilder jobBuilder = jobBuilderFactory.get(JobConstants.CONTENT_UPGRADE_JOB)
                .listener(upgradeJobResultListener())
                .start(initContent())
                .next(stepBuilderFactory.get("create_snapshot_tasklet").tasklet(createSnapshotTasklet()).build())
                .next(stepBuilderFactory.get("incremental_deploy_tasklet").tasklet(tasklet).build());

        return jobBuilder.build();
    }

任务:

packCompositionMap.put(incremental_content_deploy, Arrays.asList(
            create_security_actions ,slice_content, upgrade_appmodule, 
  application_refresh,
            install_reset_roles_bar, restore_reset_roles_bar,
            populate_roles, add_roles,
            replay_security_actions,
            create_adw_connection,
            apply_system_extensions,
            replay_system_steps,
            assign_service_admin
    ));

刚刚启动“ crememental_deploy_tasklet”时发送ID的停止信号,并且从数组列表中选择了“ create_security_actions”任务,但问题是它没有停止,但在数组中完成所有项目任务停止的“ regemental_deploy_tasklet”步骤,然后该作业的总体状态也被标记为停止。

我正在寻找的是帮助停止并打断此“ create_security_actions”任务本身。任何帮助或意见都将不胜感激,谢谢

I have a spring batch job and it has 3 steps, the 3rd step has some tasklet as below. Now when we try to stop the job using,

jobOperator.stop(id);

it sends the STOP signal when STEP 3 is in progress and interrupts only when all the tasklet in the STEP 3 is completed. Let's say it has 10 tasks, although we sent the stop signal when it was STEP 3 and Task 1 in progress - it does not stop there. It finishes all the 10 tasks and then marks this STEP 3 status as COMPLETED. Is there any way we can stop step 3 while processing the first task? I did see the spring batch documentation and did not find much. Below is the sample code.

Job:

   @Bean(JobConstants.CONTENT_UPGRADE_JOB)
    public Job upgradeContentJob() {
        Tasklet tasklet = context.getBean("incremental_deploy_tasklet", Tasklet.class);
        SimpleJobBuilder jobBuilder = jobBuilderFactory.get(JobConstants.CONTENT_UPGRADE_JOB)
                .listener(upgradeJobResultListener())
                .start(initContent())
                .next(stepBuilderFactory.get("create_snapshot_tasklet").tasklet(createSnapshotTasklet()).build())
                .next(stepBuilderFactory.get("incremental_deploy_tasklet").tasklet(tasklet).build());

        return jobBuilder.build();
    }

Tasks:

packCompositionMap.put(incremental_content_deploy, Arrays.asList(
            create_security_actions ,slice_content, upgrade_appmodule, 
  application_refresh,
            install_reset_roles_bar, restore_reset_roles_bar,
            populate_roles, add_roles,
            replay_security_actions,
            create_adw_connection,
            apply_system_extensions,
            replay_system_steps,
            assign_service_admin
    ));

Here STOP signal for the id is sent when "incremental_deploy_tasklet" is just initiated and "create_security_actions" task is picked from the array list but the problem is it does not stops but completes all the item task in the array and then marks the status for this "incremental_deploy_tasklet" step as STOPPED and then overall status for this job is also marked as STOPPED.

What I am looking for is help on to STOP and interrupt at this "create_security_actions" task itself. Any help or input is appreciated, Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆离笙 2025-02-19 05:57:41

阅读了多个文档并尝试 - 发现我们无法立即终止线程。控件应返回框架。
关闭不是立即的,因为没有办法迫使立即关闭,尤其是如果当前执行在开发人员代码中,该框架无法控制,例如商业服务。但是,一旦控件返回框架,它将将当前的stepexecution的状态设置为batchstatus.stopped,保存,然后在完成之前对Jobexecution进行相同的操作。

谢谢。

After reading multiple docs and trying it- found that we cannot terminate the thread immediately. The control should come back to the framework.
The shutdown is not immediate, since there is no way to force an immediate shutdown, especially if the execution is currently in developer code that the framework has no control over, such as a business service. However, as soon as control is returned back to the framework, it will set the status of the current StepExecution to BatchStatus.STOPPED, save it, then do the same for the JobExecution before finishing.

Thank you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文