0

Getting deadlock while using AsyncItemWriter

I am using AsyncItemProcessor and AsyncItemWriter to implement parallel processing in spring batch. I am trying to read some data from a table, and processing the data read in multiple threads and after performing some logic, writing the processed data to a destination table using AsyncItemWriter.

I am getting the following exception frequently:

org.springframework.retry.ExhaustedRetryException: Retry exhausted after last attempt in recovery path, but exception is not skippable.; nested exception is org.springframework.dao.DeadlockLoserDataAccessException: StatementCallback; SQL [SELECT * FROM .. WHERE .. order by id desc ]; An error occurred during the current command (Done status 0). Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: An error occurred during the current command (Done status 0). Transaction (Process ID 66) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

Following is my Step creation:

@Bean
    public Step eventMessagesStep() {
        return stepBuilderFactory
                .get(EVENTMESSAGES_STEP)
                .<EventMessagesReaderDTO, Future<RequestDataDTO>>chunk(chunk)
                .reader(eventMessagesPagingItemReader())
                .processor(asyncProcessor())
                .writer(asyncWriter())
                .faultTolerant().skipPolicy(jsonSkipPolicy())
                .retry(DeadlockLoserDataAccessException.class)
                .taskExecutor(taskExecutor())
                .build();

0 Answers0