'How to get chunk size in my ItemReader class

  1. JobConfig
@RequiredArgsConstructor
@Configuration
public class SampleJobConfig {
    private static final int JOB_CHUNK_SIZE = 100;

    private final JobBuilderFactory jobBuilderFactory;
    private final StepBuilderFactory stepBuilderFactory;

    private final SampleItemProvider sampleItemProvider; // custom class : itemReader, itemProcessor, itemWriter

    @Bean
    public Job myJob() {
        return jobBuilderFactory.get("myJob").start(myStep()).build();
    }

    @Bean
    @JobScope
    public Step myStep() {
        return stepBuilderFactory.get("myStep")
                .<String, String>chunk(JOB_CHUNK_SIZE)
                .reader(sampleItemReader)
                .processor(sampleItemProvider)
                .writer(sampleItemProvider)
                .build();
    }
}
  1. StepProvider : Another Class

@RequiredArgsConstructor
@Component
@StepScope
public class SampleItemProvider extends AbstractPaginItemReader<String> implements ItemProcessor<String, String>, ItemWriter<String> {
    
    @Override
    protected void doReadPage() {
        // ** I want to get the chunk size set to "SampleJobConfig -> StepBuilder" from here. **
        // not Variable declaration
        // not magic number 
        // I want to get the chunksize that I took over when this StepScope was called.

    }

    // ..... Processor and Writer
}

** I want to get the chunk size set to "SampleJobConfig -> StepBuilder" from here. **

not Variable declaration

not magic number

Want to get the chunksize that I took over when this StepScope was called....



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source