2

I had spring batch application and configured step like this:

ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(4);
taskExecutor.setMaxPoolSize(10);
taskExecutor.afterPropertiesSet();
return this.stepBuilderFactory.get("step1")
            .<Mymodel, Mymodel>chunk(2500)              
            .reader(reader())
            .writer(writer())
            .taskExecutor(taskExecutor)
            .build();

And reader like this:

@Bean
public JdbcCursorItemReader<Mymodel> reader() {
    JdbcCursorItemReader<Mymodel> reader = new JdbcCursorItemReader<Mymodel>();
    reader.setDataSource(dataSource);
    reader.setSql("select * from User");
    reader.setRowMapper(new BeanPropertyRowMapper<>(Mymodel.class));
    reader.setVerifyCursorPosition(false);
    return reader;
}

When I execute application , getting this error:

org.springframework.jdbc.UncategorizedSQLException: Attempt to process next row failed; uncategorized SQLException for SQL [select * from User]; SQL state [99999]; error code [17289]; Result set after last row; nested exception is java.sql.SQLException: Result set after last row

Can you please help me to solve this.

daedsidog
  • 1,732
  • 2
  • 17
  • 36
Kumar
  • 35
  • 2
  • 7
  • Yes, per my experience and observations above combination doesn't seem to be working well. – PAA Jun 21 '20 at 12:54

1 Answers1

0

The JdbcCursorItemReader is not thread-safe as it wraps a ResultSet object which is not thread safe.

You can use a JdbcPagingItemReader which is thread safe and optionally configure the page size to match the chunk size so that each page is processed in the same thread.

More details in the following answer: https://stackoverflow.com/a/28724199/5019386.

Hope this helps.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50
  • When I tried above approach, my application able to read configured page size and remaining records will not processed. I had added task executor as well. if I give page size as 2000 , application able to process 6000 records and stopped processing. Please help me. – Kumar Dec 30 '18 at 05:13
  • That's another issue, so please ask a different question on SO. My answer should have fixed your issue with the `JdbcCursorItemReader`, if it is the case, please accept it and I will try to help you with your question regarding the `JdbcPaginingItemReader`. – Mahmoud Ben Hassine Jan 02 '19 at 09:47
  • Sure, Can you help me any example having JdbcPaginingItemReader, some reason I am not able to proceed with next page. – Kumar Jan 02 '19 at 19:35
  • You can find an example of how to use the `JdbcPagingItemReader` here: https://github.com/spring-projects/spring-batch/blob/master/spring-batch-samples/src/main/resources/jobs/iosample/jdbcPaging.xml – Mahmoud Ben Hassine Jan 02 '19 at 20:25