English 中文(简体)
Is it possible to catch and retry exceptions thrown by a ChunkListener in Spring Batch?
原标题:

I configured the CustomChunkListener. I created to check the status of redis Distributed lock and throw an Custom Exception if it is locked.

In Step, of Custom Exception is caught with fault Tolerant, Step is configured to be re-executed up to 3 times.

However, FaultTolerantStepBuilder delegates ChunkListener to TerminateOnExceptionChunkListenerDelegate class and throws FatalStepExecutionException. Unable to catch CustomException

my code sample.

public Class MyBatchConfig {

    public Step MyBatchStep() {
        return stepBuilderFactory.get("refineCarStatusStep")
                                    .<I, O>chunk(CHUNK_SIZE)
                                    .reader(MyItemReader())
                                    .processor(MyItemProcessor())
                                    .writer(MyItemWriter())
                                    .faultTolerant()
                                    .retry(CustomException.class)
                                    .retryLimit(3)
                                    .listener(new CustomChunkListener())
                                    .build();
    }
}

public class CustomChunkListener implements ChunkListener {

    @Override
    public void beforeChunk(ChunkContext context) {
        // example. redis Distributed lock check
        if(isLocked) {
            throw new CustomException();
        }
    }

    @Override
    public void afterChunk(ChunkContext context) {
        unlock();
    }

    @Override
    public void afterChunkError(ChunkContext context) {
        unlock();
    }
}

How can I throw, catch and retry an exception before the start of the chunk?

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签