<commit_before>package org.drools.persistence;

import java.util.Set;
import java.util.TreeSet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TransactionSynchronizationContainer implements TransactionSynchronization {

    private static Logger logger = LoggerFactory.getLogger( TransactionSynchronizationContainer.class );
    public static final String RESOURCE_KEY = "org.drools.persistence.txsync.container";

    private Set<TransactionSynchronization> synchronizations = new TreeSet<TransactionSynchronization>();

    @Override
    public void beforeCompletion() {
        for (TransactionSynchronization txSync : synchronizations) {
            txSync.beforeCompletion();
        }
    }

    @Override
    public void afterCompletion(int status) {
        for (TransactionSynchronization txSync : synchronizations) {
            txSync.afterCompletion(status);
        }
    }

    public void addTransactionSynchronization(TransactionSynchronization txSync) {
        this.synchronizations.add(txSync);
        logger.debug("Adding sync {} total syncs ", txSync, synchronizations.size());
    }
}<commit_msg>avoid concurrent modification exceptions in edge cases by using iterator<commit_after>package org.drools.persistence;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TransactionSynchronizationContainer implements TransactionSynchronization {

    private static Logger logger = LoggerFactory.getLogger( TransactionSynchronizationContainer.class );
    public static final String RESOURCE_KEY = "org.drools.persistence.txsync.container";

    private Set<TransactionSynchronization> synchronizations = new TreeSet<TransactionSynchronization>();

    @Override
    public void beforeCompletion() {
        Iterator<TransactionSynchronization> it = synchronizations.iterator();
        while (it.hasNext()) {

            TransactionSynchronization txSync = it.next();
            txSync.beforeCompletion();
        }
    }

    @Override
    public void afterCompletion(int status) {
        Iterator<TransactionSynchronization> it = synchronizations.iterator();
        while (it.hasNext()) {

            TransactionSynchronization txSync = it.next();
            txSync.afterCompletion(status);
        }
    }

    public void addTransactionSynchronization(TransactionSynchronization txSync) {
        this.synchronizations.add(txSync);
        logger.debug("Adding sync {} total syncs ", txSync, synchronizations.size());
    }
}
{'fraction_non_alphanumeric': 0.08346273291925466, 'fraction_numerical': 0.0015527950310559005, 'mean_word_length': 3.8992395437262357, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4159569', 'n_tokens_mistral': 654, 'n_tokens_neox': 636, 'n_words': 143}