In addSynchronization for TwoPhaseCoordinator, the synchronization object is created if it isn't already set:
if (_synchs == null)
{
// Synchronizations should be stored (or at least iterated) in their natural order
_synchs = new TreeSet();
}
if (_synchs.add(sr))
{
result = AddOutcome.AR_ADDED;
}
However, because multiple threads could be calling the same transaction instance concurrently, shouldn't there be a synchronization around this block? It's possible that two threads could test and try to set the _synchs and because of interleaving one thread creates _synchs after the other thread already has and added it's resource (which would then become garbage).