Well I found the problem already and you are right it is impossible for the DataSource to return the same connection given the underlying pool management behind it. I've taken a look at the connection wrapper class I was using and realized that it was not
thread safe, making it return the same connection.
Basically the class has an instance Connection variable which is set during calls to connect().
public void connect(){
:
:
connection = myDataSource.getConnection();
:
}
and returns the connection through a getter
public Connection getConnection(){
return connection;
}
This probably will work fine in most cases, however I was using this class in a multi-threaded fashion such that if two threads simultaneously call connect(), the last connection retrieved will have overwritten the initial connection stored in the instance variable. Resulting in my using the same connection in both threads which is a violation of the latest
J2EE specification.