Author: kristwaa Date: Tue Jul 5 10:05:36 2011 New Revision: 1142956 URL: http://svn.apache.org/viewvc?rev=1142956&view=rev Log: DERBY-4137: OOM issue using XA with timeouts DERBY-5291: test failure: NullPointerException with J2ME (weme 6.2) in testDerby4137_TransactionTimeoutSpecifiedNotExceeded(org.apache.derbyTesting.functionTests.tests.memory.XAMemTest) Merged fix from trunk (revisions 1138341 and 1136363) with manual conflict resolution in memory/_Suite (conflict with 'suite.addTest(MemoryLeakFixesTest.suite());'). Added: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java - copied, changed from r1136363, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java Modified: db/derby/code/branches/10.8/ (props changed) db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/XATransactionState.java db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java Propchange: db/derby/code/branches/10.8/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Tue Jul 5 10:05:36 2011 @@ -1,2 +1,2 @@ /db/derby/code/branches/10.7:1061570,1061578,1082235 -/db/derby/code/trunk:1063809,1088633,1091000,1091221,1091285,1092067,1092795,1094315,1094572,1094728,1096741,1096890,1097247,1097249,1097460,1097469,1097471,1101059,1101839,1102620,1102826,1103681,1103718,1103742,1125305,1126358,1126468,1127825,1127883,1129136,1129764,1129797,1130077,1130084,1130632,1130895,1131030,1131272,1132546,1132664,1132860,1132928,1133304,1133317,1133741,1133752,1136371,1136397,1136844,1138201,1138444,1138787,1138795,1139449,1139451,1141924,1142635 +/db/derby/code/trunk:1063809,1088633,1091000,1091221,1091285,1092067,1092795,1094315,1094572,1094728,1096741,1096890,1097247,1097249,1097460,1097469,1097471,1101059,1101839,1102620,1102826,1103681,1103718,1103742,1125305,1126358,1126468,1127825,1127883,1129136,1129764,1129797,1130077,1130084,1130632,1130895,1131030,1131272,1132546,1132664,1132860,1132928,1133304,1133317,1133741,1133752,1136363,1136371,1136397,1136844,1138201,1138341,1138444,1138787,1138795,1139449,1139451,1141924,1142635 Modified: db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/XATransactionState.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/XATransactionState.java?rev=1142956&r1=1142955&r2=1142956&view=diff ============================================================================== --- db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/XATransactionState.java (original) +++ db/derby/code/branches/10.8/java/engine/org/apache/derby/jdbc/XATransactionState.java Tue Jul 5 10:05:36 2011 @@ -90,17 +90,29 @@ final class XATransactionState extends C /** The implementation of TimerTask to cancel a global transaction. */ - private class CancelXATransactionTask extends TimerTask { + private static class CancelXATransactionTask extends TimerTask { - /** Creates the cancelation object to be passed to a timer. */ - public CancelXATransactionTask() { - XATransactionState.this.timeoutTask = this; + private XATransactionState xaState; + + /** + * Creates the cancellation task to be passed to a timer. + * + * @param xaState the XA state object for the transaction to cancel + */ + public CancelXATransactionTask(XATransactionState xaState) { + this.xaState = xaState; + } + + public boolean cancel() { + // nullify reference to reduce memory footprint of canceled tasks + xaState = null; + return super.cancel(); } /** Runs the cancel task of the global transaction */ public void run() { try { - XATransactionState.this.cancel(MessageId.CONN_XA_TRANSACTION_TIMED_OUT); + xaState.cancel(MessageId.CONN_XA_TRANSACTION_TIMED_OUT); } catch (Throwable th) { Monitor.logThrowable(th); } @@ -313,10 +325,10 @@ final class XATransactionState extends C // schedule a time out task if the timeout was specified if (timeoutMillis > 0) { // take care of the transaction timeout - TimerTask cancelTask = new CancelXATransactionTask(); TimerFactory timerFactory = Monitor.getMonitor().getTimerFactory(); Timer timer = timerFactory.getCancellationTimer(); - timer.schedule(cancelTask, timeoutMillis); + timeoutTask = new CancelXATransactionTask(this); + timer.schedule(timeoutTask, timeoutMillis); } else { timeoutTask = null; } @@ -354,6 +366,7 @@ final class XATransactionState extends C synchronized void xa_finalize() { if (timeoutTask != null) { timeoutTask.cancel(); + timeoutTask = null; } performTimeoutRollback = false; } Copied: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java (from r1136363, db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java) URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java?p2=db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java&p1=db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java&r1=1136363&r2=1142956&rev=1142956&view=diff ============================================================================== --- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java (original) +++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/XAMemTest.java Tue Jul 5 10:05:36 2011 @@ -30,9 +30,11 @@ import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; import junit.framework.Test; +import junit.framework.TestSuite; import org.apache.derbyTesting.junit.BaseJDBCTestCase; import org.apache.derbyTesting.junit.J2EEDataSource; +import org.apache.derbyTesting.junit.JDBC; import org.apache.derbyTesting.junit.TestConfiguration; import org.apache.derbyTesting.junit.XATestUtil; @@ -86,6 +88,10 @@ public class XAMemTest } public static Test suite() { - return TestConfiguration.defaultSuite(XAMemTest.class); + if (JDBC.vmSupportsJDBC3()) { + return TestConfiguration.defaultSuite(XAMemTest.class); + } + + return new TestSuite("XAMemTest skipped - XADataSource not available"); } } Modified: db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java?rev=1142956&r1=1142955&r2=1142956&view=diff ============================================================================== --- db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java (original) +++ db/derby/code/branches/10.8/java/testing/org/apache/derbyTesting/functionTests/tests/memory/_Suite.java Tue Jul 5 10:05:36 2011 @@ -41,6 +41,7 @@ public class _Suite extends BaseJDBCTest suite.addTest(MultiByteClobTest.suite()); suite.addTest(RolesDependencyTest.suite()); suite.addTest(Derby3009Test.suite()); + suite.addTest(XAMemTest.suite()); suite.addTest(MemoryLeakFixesTest.suite()); return suite; }