Jan Seevers
Jan Seevers

Reputation: 798

Easy way to get START_TIME from BATCH_JOB_EXECUTION

A job in Spring-batch will save status on the job in the table BATCH_JOB_EXECUTION. Is there an easy way (beside reading the column START_TIME in the table itself) to get the start time of the job from a Step?

Upvotes: 1

Views: 1304

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31710

Yes, the idea to get access to the job execution from the step execution. For example:

@Bean
public Step step() {
    return stepBuilderFactory.get("step")
            .tasklet(new Tasklet() {
                @Override
                public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
                    JobExecution jobExecution = chunkContext.getStepContext().getStepExecution().getJobExecution();
                    System.out.println("hello world! Job started at: " + jobExecution.getStartTime());
                    return RepeatStatus.FINISHED;
                }
            })
            .build();
}

Upvotes: 2

Related Questions