Index: java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java =================================================================== --- java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (revision 614200) +++ java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (working copy) @@ -337,23 +337,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) @@ -431,13 +416,28 @@ /** 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. 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; }