mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
Fix memory leak in threadLocal on implicit transactions (#1711)
* refactor TestExecutionComplete
* Add more tests to discover missing threadScope cleanups
* FIX: clear threadScope on implicit created Jdbc transactions
* FIX: clear threadScope on completed JTA transactions
* Revert "FIX: clear threadScope on completed JTA transactions"
This reverts commit f844405542.
This commit is contained in:
1 parent
2b1b4af7a2
commit
2678f85506
5 files changed
+75
-12
No files matched your search
@@ -42,5 +42,9 @@ public class DefaultTransactionScopeManager extends TransactionScopeManager {
|
||||
DefaultTransactionThreadLocal.set(serverName, trans);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(SpiTransaction trans) {
|
||||
DefaultTransactionThreadLocal.clear(serverName, trans);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,6 +40,17 @@ public final class DefaultTransactionThreadLocal {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a transaction from the ThreadLocal to prevent memory leaks.
|
||||
* Will only clear, if trans == currentTransaction
|
||||
*/
|
||||
public static void clear(String serverName, SpiTransaction trans) {
|
||||
Map<String, SpiTransaction> map = local.get();
|
||||
if (map.get(serverName) == trans) {
|
||||
map.remove(serverName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A mechanism to get the transaction out of the thread local by replacing it
|
||||
* with a 'proxy'.
|
||||
|
||||
@@ -920,6 +920,9 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
}
|
||||
connection = null;
|
||||
active = false;
|
||||
if (manager != null) {
|
||||
manager.scope().clear(this);
|
||||
}
|
||||
profileEnd();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,11 @@ public abstract class TransactionScopeManager implements SpiTransactionScopeMana
|
||||
*/
|
||||
public abstract void set(SpiTransaction trans);
|
||||
|
||||
/**
|
||||
* Clears the given Transaction for this serverName and Thread.
|
||||
*/
|
||||
public abstract void clear(SpiTransaction trans);
|
||||
|
||||
/**
|
||||
* Replace the current transaction with this one.
|
||||
* <p>
|
||||
|
||||
Reference in new issue
Block a user