I'm heavy testing some ejb app we made using openejb and we are getting lot's of Database is closed exceptions in JdbcConnection. I've been reading the source code and found this method:
/**
* Invoked by the JdbcConneciton when its close() method is called.
* This method invalidates the JdbcConnection handle, removes it from
* the list of active handles and notifies all the ConnectionEventListeners.
*/
protected void connectionClose(JdbcConnection jdbcConn){
jdbcConn.invalidate();
jdbcConnections.remove(jdbcConn);
ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
Object [] elements = listeners.toArray();
for(int i = 0; i < elements.length; i++){
ConnectionEventListener eventListener = (ConnectionEventListener)elements[i];
eventListener.connectionClosed(event);
}
}
in JdbcManagedConnection.java
i think that this code has "a problem" with concurrency... if two thread's (or 2 ejb beans) are sharing the same connection, (it seams that is could be possible, because i didn't find code that inform's if a connection is being used or not (maybe i haven't looked right)) and one of the threads call the close method, the first thing that it does, is to nullify all object's, and then remove if from the pool, however, supose that while the thread 1 is nullifying the objects and thread 2 is getting the same connection from the pool (because it will only removed from pool, after nullifying all objects) thread 2 will get a NullPointerException, right?
Shouldn't we call jdbcConn.invalidate(); in the end of the method? or after removing it from the pool, so noone would be a null connection?
Some thing like:
/**
* Invoked by the JdbcConneciton when its close() method is called.
* This method invalidates the JdbcConnection handle, removes it from
* the list of active handles and notifies all the ConnectionEventListeners.
*/
protected void connectionClose(JdbcConnection jdbcConn){
jdbcConnections.remove(jdbcConn);
ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
Object [] elements = listeners.toArray();
for(int i = 0; i < elements.length; i++){
ConnectionEventListener eventListener = (ConnectionEventListener)elements[i];
eventListener.connectionClosed(event);
}
jdbcConn.invalidate();
}
Even better, synchronize the jdbcConnections object?
I'm writting this, because my app works fine with a few client's but under heavy loadind (it's a web portal) i get lot's of null pointer exceptions in JdbcConnection.java...
Any ideas?
--
<<inline: netvita.gif>>
