Spring Batch:How to monitor currently running jobs & show progress on jsp page

南笙酒味 提交于 2019-12-21 06:16:11

问题


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.


回答1:


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.


Edit to reply for the comment:

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).

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.




回答2:


You should have a look at spring batch admin application.

Spring Batch Admin

To quote directly: It's a regular war file. Once it's deployed, you can browse with a web browser (e.g. localhost:8080/spring-batch-admin-sample) and check out the features for launching jobs and inspecting job executions.

Surely, through some modifications, you can achieve your own requirement.




回答3:


Spring Batch ver 4.2 comes with batch monitoring and metrics capturing based on Micrometer .You can try to leverage the same. Following table list some of the metrics

Spring Batch also enables you to create your own metrics .You can check more details here https://docs.spring.io/spring-batch/4.2.x/reference/html/monitoring-and-metrics.html#custom-metrics



来源:https://stackoverflow.com/questions/13450952/spring-batchhow-to-monitor-currently-running-jobs-show-progress-on-jsp-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!