Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
408 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...