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

21,104

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

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

Solution 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 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

Share:
21,104
Dangling Piyush
Author by

Dangling Piyush

Just a Random Guy

Updated on June 27, 2020

Comments

  • Dangling Piyush
    Dangling Piyush about 4 years

    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.