2 Replies Latest reply on Mar 29, 2005 11:42 PM by sriramp_here

    Connection Pooling In JBOSS

      Hi,
      I am Using oracle as the datasource. I have a doubt whether I should write any connection pool for the JBoss app Server.Lets Say I have a maximum of
      15 connections configured in my oracle-xa-da.xml. I have pasted my oracle-xa-ds below.


      <xa-datasource>
      <jndi-name>XAOracleDS</jndi-name>
      <track-connection-by-tx/>
      <isSameRM-override-value>false</isSameRM-override-value>
      <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
      <xa-datasource-property name="URL">jdbc:oracle:oci8:@tc</xa-datasource-property>
      <xa-datasource-property name="User">scott</xa-datasource-property>
      <xa-datasource-property name="Password">tiger</xa-datasource-property>
      <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
      <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
      <!-- Checks the Oracle error codes and messages for fatal errors -->
      <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
      <min-pool-size>5</min-pool-size>

      <!-- The maximum connections in a pool/sub-pool -->
      <max-pool-size>20</max-pool-size>

      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
      <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
      <no-tx-separate-pools/>
      </xa-datasource>


      <depends optional-attribute-name="TransactionManagerService">jboss:service=TransactionManager





      I have written a connection pool class as shown below.

      import java.sql.*;
      import javax.sql.*;
      import javax.naming.*;

      public class DBConnector {
      public Connection getConnection(){

      try {

      Context ctx = new InitialContext();

      DataSource ds = (DataSource) ctx.lookup("java:/DevelopmentDS");

      return ds.getConnection();

      }catch(Exception exe){

      System.out.println ("The exception is " + exe);

      return null;

      }

      }


      public void closeConnection (PreparedStatement stmt, ResultSet rs, Connection con){


      try{

      if (stmt != null){

      stmt.close();

      }

      if (rs != null){

      rs.close();

      }

      if (con != null){

      con.close();

      }

      }catch(Exception exe){

      }

      }

      }

      If 25 different Session Beans tries to get the connection from the pool
      what will happen, will JBoss internally Queue the Bean until they get a connection. Please help me

      Regards
      Sriram.P


        • 1. Re: Connection Pooling In JBOSS
          schrouf

          20 SB will 'immediately' (after connection creation) get a connection from the JBoss connection pool on call to ds.getConnection()

          5 SB will block until a previously allocated connection is returned to JBoss connection pool ( by a call to con.close()).

          If no connection gets available within the configured timeout, the waiting SB will get an exception "No managed connection available within the configured timeout periode"

          That's why connections should be returned to JBoss pool as fast as possible !

          Regards
          Ulf

          • 2. Re: Connection Pooling In JBOSS

            Hi
            Thanks a lot for the explanation.
            Regards
            Sriram.