commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eslam M. Abbass" <Eslam.Abb...@itworx.com>
Subject Am I configuring my connection pool right?
Date Thu, 06 Oct 2005 10:53:33 GMT
Hi all-

            I need to make sure that am I configuring my connection pool
right?

 

Here is my class that generates the connection to the needed DAO

 

   private static GenericObjectPool connectionPool = null;

 

    private static ConnectionFactory connectionFactory = null;

 

    private static PoolableConnectionFactory poolableConnectionFactory =
null;

 

    private static PoolingDriver driver = null;

 

    static

    {

        try

        {

 

String userName = username;

            String password = password;

            String connectURI = jdbc:oracle:thin:@10.30.0.190:1521:test;

            String driverClass =oracle.jdbc.driver.OracleDriver;

            int maxActiveConnections = 50;

            long maxWaitTime = 10;

 

            Class.forName(driverClass);

 

            connectionPool = new GenericObjectPool(null);

            connectionPool.setMaxActive(maxActiveConnections);

            connectionPool.setMaxWait(maxWaitTime);

 

            connectionFactory = new
DriverManagerConnectionFactory(connectURI,

                    userName, password);

 

            poolableConnectionFactory = new PoolableConnectionFactory(

                    connectionFactory, connectionPool, null, null,
false, true);

 

            Class.forName("org.apache.commons.dbcp.PoolingDriver");

 

            driver = (PoolingDriver) DriverManager

                    .getDriver("jdbc:apache:commons:dbcp:");

            driver.registerPool("example", connectionPool);

 

       }

        catch (ClassNotFoundException exception)

        {

            Logging

                    .getLogger()

                    .fatal(

                            exception.getMessage()

                                    + " from DatabaseUtility while
intialize the oracle driver");

        }

        catch (SQLException exception)

        {

            Logging.getLogger().fatal(

                    exception.getMessage() + " from
BaseDAO.getConnection()");

        }

 

 

    /**

     * getPooledConnection-- Method to return the pooled connection and
read it

     * once from the main.properties file

     * 

     * @return Connection

     */

    public static Connection getPooledConnection() throws SQLException

    {

        Connection connection = DriverManager

                .getConnection("jdbc:apache:commons:dbcp:example");

        printDriverStats();

         return connection;

//        return new PoolableConnection(connection, connectionPool);

 

    }

 

Can any one guide me is this how we can make connection pooling and how
can I test that the connection is pooled and destroyed etc.

 

Best regards,

Eslam M.Abbass

Team Leader

ITWorx Egypt

www.itworx.com

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message