2 Replies Latest reply on Apr 12, 2006 11:58 AM by Vasco Costa

    JCA pooling

    Vasco Costa Newbie

      Hello,

      I am developing a custom JCA connector. In it, I have a matchManagedConnections method which discriminates by username. in pseudocode:

      public ManagedConnectionFactory {
      Connection matchManagedConnections(Set set, ConnectionRequestInfo info) {
       iterate (set) {
       if (setItem.info.equals(info)) {
       return setItem.conn;
       }
       }
       return null;
      }
      
      public ConnectionRequestInfo {
       String username;
      
       boolean equals(other) {
       return username.equals(other.username);
       }
      }
      


      Creating a connection is very expensive in this connector (establishing a connection takes ~300-400ms).

      Connection pool management does not happen as I expected, maybe I should be doing something differently, but for e.g. this happens:

      * User A, B, C getConnection() (JBoss invokes createManagedConnection) and then the users close() their connection.

      * User B tries to getConnection() again.
      * JBoss calls matchManagedConnections passing a set with the singleton A user connection in the pool. matchManagedConnections returns null and the connection to A is destroyed.
      * JBoss calls matchManagedConnections passing a set with the singleton B user connection in the pool. matchManagedConnections returns the B connection.

      * User A tries to getConnection() again.
      * JBoss calls matchManagedConnections passing a set with the singleton C user connection in the pool. matchManagedConnections returns null and the connection to C is destroyed.
      * JBoss calls createManagedConnections for A because the pool is empty.

      * User C tries to getConnection() again.
      * JBoss calls createManagedConnections for C because the pool is empty.

      How can I avoid premature destruction of connections because of a bad connection match like this?

      Thank you for reading,
      -Vasco Alexandre da Silva Costa