You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2008/01/31 01:24:11 UTC
svn commit: r616966 -
/db/derby/code/branches/10.2/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
Author: kmarsden
Date: Wed Jan 30 16:24:10 2008
New Revision: 616966
URL: http://svn.apache.org/viewvc?rev=616966&view=rev
Log:
DERBY-2142 NullPointerException while using XAConnection/PooledConnection in a heavily contended multithreaded scenario
port from trunk, revisions 616141,616575
Modified:
db/derby/code/branches/10.2/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
Modified: db/derby/code/branches/10.2/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=616966&r1=616965&r2=616966&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original)
+++ db/derby/code/branches/10.2/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Wed Jan 30 16:24:10 2008
@@ -320,23 +320,8 @@
}
}
- // my conneciton handle is being closed
- public synchronized void notifyClose()
- {
- // tell my listeners I am closed
- if (eventListener != null && eventListener.size() > 0)
- {
- ConnectionEvent closeEvent = new ConnectionEvent(this);
- for (Enumeration e = eventListener.elements();
- e.hasMoreElements(); )
- {
- ConnectionEventListener l =
- (ConnectionEventListener)e.nextElement();
- l.connectionClosed(closeEvent);
- }
- }
- }
+
final void checkActive() throws SQLException {
if (!isActive)
@@ -414,13 +399,37 @@
/**
Close called on BrokeredConnection. If this call
returns true then getRealConnection().close() will be called.
-
+
+
+ Notify listners that connection is closed.
Don't close the underlying real connection as
it is pooled.
*/
- public boolean closingConnection() throws SQLException {
- notifyClose();
+ public synchronized boolean closingConnection() throws SQLException {
+ //DERBY-2142-Null out the connection handle BEFORE notifying listeners.
+ //At time of the callback the PooledConnection must be
+ //disassociated from its previous logical connection.
+ //If not there is a risk that the Pooled
+ //Connection could be returned to the pool, ready for pickup by a
+ //new thread. This new thread then might obtain a java.sql.Connection
+ //whose reference might get assigned to the currentConnectionHandle
+ //field, meanwhile the previous thread completes the close making
+ //the newly assigned currentConnectionHandle null, resulting in an NPE.
currentConnectionHandle = null;
+ // tell my listeners I am closed
+ if (eventListener != null && eventListener.size() > 0)
+ {
+ ConnectionEvent closeEvent = new ConnectionEvent(this);
+
+ for (Enumeration e = eventListener.elements();
+ e.hasMoreElements(); )
+ {
+ ConnectionEventListener l =
+ (ConnectionEventListener)e.nextElement();
+ l.connectionClosed(closeEvent);
+ }
+ }
+
return false;
}