I set the chunk size to 15 and the page size to 15 at the time of programming, and made the batch program run every minute and 1 second. The result I want is, for example, when I have 30 data, I process 15 data in the first second and then 15 data in the immediately following page. But the way it works now is that it processes 15 data in the first second, then another 15 in the next second, and so on. Is there a way to do an action until the end of the page when executed once?
@Bean
public Job ConfirmJob() throws Exception {
Job exampleJob = jobBuilderFactory.get("ConfirmJob")
.start(Step())
.build();
return exampleJob;
}
@Bean
@JobScope
public Step Step() throws Exception {
return stepBuilderFactory.get("Step")
.<UserOrder,UserOrder>chunk(15)
.reader(reader())
.processor(processor())
.writer(writer())
.build();
}
@Bean
@StepScope
public JpaPagingItemReader<UserOrder> reader() throws Exception {
Map<String,Object> parameterValues = new HashMap<>();
parameterValues.put("beforeDay", LocalDateTime.now().minusDays(14));
parameterValues.put("od", OrderStatus.ship);
return new JpaPagingItemReaderBuilder<UserOrder>()
.pageSize(15)
.parameterValues(parameterValues)
.queryString("SELECT uo FROM UserOrder uo where uo.standardfinishAt <: beforeDay And uo.orderStatus =: od ORDER BY id ASC")
.entityManagerFactory(entityManagerFactory)
.name("JpaPagingItemReader")
.build();
}
@Bean
@StepScope
public ItemProcessor<UserOrder, UserOrder> processor(){
return new ItemProcessor<UserOrder, UserOrder>() {
@Override
public UserOrder process(UserOrder us) throws Exception {
us.batchConfirm(LocalDateTime.now());
return us;
}
};
}
@Bean
@StepScope
public JpaItemWriter<UserOrder> writer(){
return new JpaItemWriterBuilder<UserOrder>()
.entityManagerFactory(entityManagerFactory)
.build();
}
}
this is scheduler code
@Autowired
private ResignConfiguration resignConfiguration;
@Scheduled(cron = "1 * * * * ?")
public void runConfirmJob() {
Map<String, JobParameter> confMap = new HashMap<>();
confMap.put("time", new JobParameter(System.currentTimeMillis()));
JobParameters jobParameters = new JobParameters(confMap);
try {
jobLauncher.run(jobConfiguration.ConfirmJob(), jobParameters);
} catch (JobExecutionAlreadyRunningException | JobInstanceAlreadyCompleteException
| JobParametersInvalidException | org.springframework.batch.core.repository.JobRestartException e) {
log.error(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}