SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
template.setCompletionPolicy(new SimpleCompletionPolicy(4));
taskExecutor.setConcurrencyLimit(2);
template.setTaskExecutor(taskExecutor);
template.setExceptionHandler(new ExceptionHandler() {
@Override
public void handleException(RepeatContext context, Throwable throwable) throws Throwable {
count++;
}
});