Here is my spring batch config (relevant part) :
So this is just a job calling one step which is a tasklet.Code:<batch:job id="fakeJob" parent="simpleJob"> <batch:step id="fakeLongJobStep" parent="simpleStep"> <batch:tasklet ref="mytasklet" /> </batch:step> </batch:job>
What I want to do is to report the progress inisde the tasklet.
At first, I tried :
Then, from another thread (i.e another XHR request to my webapp), I ask for the current progress :Code:public class MyTasklet implements Tasklet { @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { JobExecution e = chunkContext.getStepContext().getStepExecution().getJobExecution(); for (i = 0; i < 100; i++) { e.getExecutionContext().put("progress", i+"/100"); Thread.sleep(2000); //simulate heavy operation } } }
This always return null except when the job is finished (which then report 99/100)Code:public String readProgress(int executionId) { return jobExplorer.getJobExcution(executionId).getExecutionContext().get("progress"); }
From what I understand, this is logical since the JobExecution is NOT persisted during the execution of a step (only persisted after).
How can I do to track the progress ?
The first thing I tried was to inject JobRepository into my tasklet and call jobRepository.updateExecutionContext(jobExecution) .
I assume this does not work since the transaction is not commited (hence, other threads still do not see the progress).
So how can I do ? Should I use a TransactionTemplate for each heavy operation or something like that ?
Please, note that using the reader->writer paradigm is not possible in my case (ask details if you need to know why).


).
Reply With Quote