Hi all,
i would like to build a batch job to update some data in a db table. My idea is to select the "oldest"/"next to be updated" rows or ids from the table and parallel fetch the new data via a webservice for those rows, store the new information per thread/row and proceed.
I would therefor like to use the TaskExecutorPartitionHandler to "execute the partitioned {@link Step} locally in multiple threads" (as the javadoc is telling me).
My Bean is:
I have setup the Job, Repository, the master step, StepExecutionSplitter and TaskExecutor as:Code:@Bean public PartitionHandler partitionHandler() throws Exception { TaskExecutorPartitionHandler partitionHandler = new TaskExecutorPartitionHandler(); partitionHandler.setGridSize(gridSize); partitionHandler.setStep(step); partitionHandler.setTaskExecutor(taskExecutor()); return partitionHandler; }
In the partitioner [1] i use a repository to get some data (ids) and store them in a map of ExecutionContexts. All missing variable declarations are @Autowired - so far no problem.Code:@Bean public Job myJob() throws Exception { SimpleJob job = new SimpleJob("My Job"); job.setJobRepository(jobRepository()); job.addStep(stepMaster()); return job; } @Bean public JobRepository jobRepository() throws Exception { MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(); jobRepositoryFactory.setTransactionManager(jpaTransactionManager); jobRepositoryFactory.setIsolationLevelForCreate("ISOLATION_DEFAULT"); return jobRepositoryFactory.getJobRepository(); } @Bean public Step stepMaster() throws Exception { PartitionStep stepMaster = new PartitionStep(); stepMaster.setPartitionHandler(partitionHandler()); stepMaster.setStepExecutionSplitter(stepExecutionSplitter()); stepMaster.setJobRepository(jobRepository()); return stepMaster; } @Bean public StepExecutionSplitter stepExecutionSplitter() throws Exception { SimpleStepExecutionSplitter stepExecutionSplitter = new SimpleStepExecutionSplitter(); stepExecutionSplitter.setJobRepository(jobRepository()); stepExecutionSplitter.setStepName("My step"); stepExecutionSplitter.setPartitioner(partitioner); // [1] return stepExecutionSplitter; } @Bean public TaskExecutor taskExecutor() { SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor(); return taskExecutor; }
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?
I also see the the job is only starting the first (gridSize) threads and then stops. Whats the issue there? Im starting it with a @Scheduled method in conjunction with a class implementing the JobLauncher.
Thanks for your help.
Best regards, Ullrich


Reply With Quote