如何使用带有多线程的JdbcCursorItemReader从Oracle Db读取数据

时间:2018-12-27 03:03:44

标签: spring spring-boot spring-batch

我有spring批处理应用程序,并配置了以下步骤:

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();

像这样的读者:

@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;
}

执行应用程序时,出现此错误:

  

org.springframework.jdbc.UncategorizedSQLException:尝试处理下一个   行失败; SQL的未分类SQLException [从用户中选择*];的SQL   状态[99999];错误代码[17289];结果集在最后一行之后;嵌套的   异常是java.sql.SQLException:结果集位于最后一行之后

能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

.model small .stack 64 .data B db ? C db ? D dw ? Array DB 20 DUP(0), '$' Array_2 DB 8 DUP(0), '$' print_1 DB 13,10,"Please Enter A Number : 0< Number <13 --- And After 2 Digit Input '+' : Examlpe : 11+ :",13,10,"$" print_2 DB 13,10,"Fibonacci Series : $" Print_3 DB " $" .code ;**************************************************************** main proc far mov ax,@data mov ds,ax call RequestP ; call Input ; call Process ;Callings call AnswerP ; call Output ; mov ax,4c00h int 21h ;********************************************************* main endp RequestP proc near mov AH, 9 lea DX, print_1 ;Printing the requestP int 21h ret RequestP endp ;********************************************************* Input proc near mov ax,0 MyLoop0: mov ah,01 int 21h cmp al,'+' je GoOut sub al,30h ;Getting Users Number add B,al mov al,B mov ah,10 mul ah mov B,al jmp MyLoop0 GoOut: mov bl,10 mov al,B mov ah,0 div bl mov B,al inc B ret Input endp ;********************************************************* Process proc near mov cl,B lea si,Array+1 mov [si-1],1 ;Defining the Array mov [si],1 MyLoop: mov [si+1],0 mov bx,[si-1] mov dx,[si] mov bh,0 add bx,dx ;Processing Code&Putting in the Array mov [si+1],bx inc si dec cl cmp cl,0 jne MyLoop ret Process endp ;********************************************************* AnswerP proc near mov AH, 9 lea DX, print_2 ;Printing the answerP int 21h ret AnswerP endp ;********************************************************* Output proc near mov cl,B lea si,Array MyLoop2: call PrintSpace call GetDigit ;Printing Digits inc si dec cl cmp cl,0 jne MyLoop2 ret Output endp ;********************************************************* GetDigit proc near mov di,0 MyLoop3: mov ax,[si] mov ah,0 mov bl,10 div bl add ah,30H ;Printing Digits Proccess mov Array+di,ah inc di mov [si],al cmp al,0 jne MyLoop3 MyLoop4: dec di mov dl,Array+di mov ah,02 ;Reversing the Digits int 21h cmp di,0 jne MyLoop4 ret GetDigit endp ;********************************************************* PrintSpace proc near mov AH, 9 lea DX, print_3 ;Printing Space int 21h ret PrintSpace endp end main ;*************************************************************** MSDN,因为它包装了一个线程安全的JdbcCursorItemReader对象。

您可以使用not thread-safeResultSet,还可以选择配置页面大小以匹配块大小,以便在同一线程中处理每个页面。

以下答案中的更多详细信息:is thread safe

希望这会有所帮助。