[AMQ-8400] Add synchronization handling for Transaction to prevent CME (#720)

This commit is contained in:
Matt Pavlovich 2021-12-20 08:37:56 -06:00 committed by GitHub
parent ee768a28d6
commit b196e9a88a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 24 deletions

View File

@ -87,16 +87,20 @@ public abstract class Transaction {
}
public Synchronization findMatching(Synchronization r) {
synchronized(synchronizations) {
int existing = synchronizations.indexOf(r);
if (existing != -1) {
return synchronizations.get(existing);
}
}
return null;
}
public void removeSynchronization(Synchronization r) {
synchronized(synchronizations) {
synchronizations.remove(r);
}
}
public void prePrepare() throws Exception {
@ -121,26 +125,32 @@ public abstract class Transaction {
}
protected void fireBeforeCommit() throws Exception {
synchronized(synchronizations) {
for (Iterator<Synchronization> iter = synchronizations.iterator(); iter.hasNext();) {
Synchronization s = iter.next();
s.beforeCommit();
}
}
}
protected void fireAfterCommit() throws Exception {
synchronized(synchronizations) {
for (Iterator<Synchronization> iter = synchronizations.iterator(); iter.hasNext();) {
Synchronization s = iter.next();
s.afterCommit();
}
}
}
public void fireAfterRollback() throws Exception {
synchronized(synchronizations) {
Collections.reverse(synchronizations);
for (Iterator<Synchronization> iter = synchronizations.iterator(); iter.hasNext();) {
Synchronization s = iter.next();
s.afterRollback();
}
}
}
@Override
public String toString() {