春季批:如何监视当前正在运行的作业&在jsp页面上显示进度 [英] Spring Batch:How to monitor currently running jobs & show progress on jsp page

查看:195
本文介绍了春季批:如何监视当前正在运行的作业&在jsp页面上显示进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何监视当前正在运行的批处理作业的状态.我的作业基本上是使用一些默认步骤来处理文件夹,因此我想逐步向用户显示进度.我正在使用

I want to know how to monitor status of my currently running batch jobs.My jobs are basically processing folder with some default steps so I want to show progress to the user step by step .I am using Tasklets and DB Job Repository.Explaining with some example code for achieving this will be more helpful.
Thank you.

推荐答案

如果要开发自己的监视器应用程序/网页,则可能需要查看JobExplorerJobOperator界面.它为您提供了获取JobExecutions的方法,在JobExecutions中,您可以获取StepExecutions.所有这些都为您提供了工作状态以及内部的各个步骤.

If you want to develop your own monitor app/webpage, you may want to look into the JobExplorer or JobOperator interface. It provides you with methods to get the JobExecutions, and in JobExecutions, you can get StepExecutions. All these give you the status of the job and individual steps inside.

编辑以回复评论:

对于引用的进度信息,它不是存储在Spring Batch中的东西.但是,这两个界面确实可以帮助您.首先将进度信息存储在步骤执行上下文中.然后,确保您的tasklet没有实现为同步任务.您必须返回CONTINUABLE(如果我混淆了这个术语,请原谅我,我以前使用过Spring Batch已经有一段时间了),以便您的tasklet将被Spring Batch连续调用. (这可以通过多种方式完成,要么将工作分解为一部分,并且每次调用tasklet execute(),就只能处理其中一部分,并且仅在所有部分完成后才返回FINISHED,或者可以生成另一个线程来完成工作,而您的小任务只需监视进度等).

For the quoted progress information, it is not something stored in Spring Batch. However, the two interface DO help you on that. First Store the progress information in the step execution context. Then make sure your tasklet is not implemented as a synchronous task. You have to return CONTINUABLE (forgive me if I mixed up the term, it have been some time I previous used Spring Batch), so that your tasklet will be invoked by Spring batch consecutively. (This can be done in many way, either you break your work into piece and for each invocation of tasklet execute(), you work on only one piece of them and return FINISHED only when all pieces is completed, or you may spawn another thread to do the work, and your tasklet simply monitor the progress, etc).

这样做,您将不断使用进度信息更新步骤执行上下文,因此您可以使用JobExplorer和JobOperator获取作业执行->步骤执行->步骤的执行上下文,以用于进度报告.

By doing so, you will have step execution context continuously updated with your progress information, so you can use JobExplorer and JobOperator to get the Job Execution -> Step Execution -> Step's Execution Context for your progress reporting purpose.

这篇关于春季批:如何监视当前正在运行的作业&在jsp页面上显示进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆