#250 Partial Rollback During Parallel Processing

Companies:
DomClick
Themes:
SpringConcurrencyTransactionsCode Review

More than 100 values are passed to process. An error occurs while processing the last value in the list. Which changes are written to the database?

@Service
public class Processor {

    @Transactional
    public void process(List<String> items) {
        if (CollectionUtils.isEmpty(items)) {
            return;
        }

        items.parallelStream()
                .forEach(this::processItem);
    }

    private void processItem(String item) {
        // insert/update item entity in DB
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in