Hi,
in the meanwhile i was able to figure out what i was missing. Thanks to the Book "Spring Batch in Action" p. 394 ff.
> My question is how do i setup the next step (ItemProcessor, ItemWriter) to fire the web requests based on the ExecutionContext i created and store the received data back?
Till now i thought the StepExecutionSplitter is an ItemReader somehow - providing the already read chunks/items whatever. Instead the StepExecutionSplitter prepares the context for each ItemReader - so we need one!
Code:
@Bean
public Step myRealStep() throws Exception
{
SimpleStepFactoryBean<ProductInformation, Integer> stepFactory = new SimpleStepFactoryBean<>();
stepFactory.setTransactionManager(transactionManager);
stepFactory.setJobRepository(jobRepository());
stepFactory.setItemReader(itemReader);
stepFactory.setItemProcessor(itemProcessor);
stepFactory.setItemWriter(itemWriter);
return (Step) stepFactory.getObject();
}
The PartitionHandler then looks like:
Code:
@Bean
public PartitionHandler partitionHandler() throws Exception
{
TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler();
partitionHandler.setGridSize(gridSize);
partitionHandler.setStep(myRealStep());
partitionHandler.setTaskExecutor(taskExecutor());
return partitionHandler;
}
Then was able to declare the ItemReader (Processor/Writer) as:
Code:
@Component
public class MyItemReader implements ItemReader<MyEntity>, ItemStream
{
private int from;
private int to;
@Override
public MyEntity read() throws Exception, UnexpectedInputException, ParseException,
NonTransientResourceException
{
// now fetch the desired entity with jpa, hibernat or something
// dont forget: this method is called until it returns "null", so save the internal state
// and return one entity after another till you reach the boundary
}
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException
{
from = executionContext.getInt("minId");
to = executionContext.getInt("maxId");
}
}
> I also see the the job is only starting the first (gridSize) threads and then stops. Whats the issue there?
I simply was creating to few ExecutionContexts with too few data. So nothing special here.
Hope this helps someone.
Regards, Ullrich