James,

I started down the same path as you and have since switched to the
BasicDataSourceFactory implementation which I think is achieving a pooled
connection.  I have a servlet implementation and connection is defined as
static.

Attached is the code.

cheers,
Dave

> Bob, thanks for the reply.
>
> I'm not using BasicDataSource at all, but maybe I should? I dunno. I
> am basing my code off of one of the examples. To create my pool:
>
> ObjectPool pool = new GenericObjectPool(null);
> ConnectionFactory conFactory =
>           new DriverManagerConnectionFactory(uri, dbUsername, dbPassword);
> PoolableConnectionFactory factory =
>           new PoolableConnectionFactory(connFactory, pool, null, null,
> true, false);
> Class.forName(driverClassName);
> Class.forName("org.apache.commons.dbcp.PoolingDriver");
> PoolingDriver driver = (PoolingDriver)
> DriverManager.getDriver("jdbc:apache:commons:dbcp:");
> driver.registerPool("myPool", pool);
>
> To use a connection:
>
>    public Connection getConn() throws SQLException {
>       return
> DrvierManager.getConnection("jdbc:apache:commons:dbcp:myPool");
>    }
>
> To return a connection:
>
>    public void releaseConn(Connection c) throws SQLException {
>       c.close();
>    }
>
> Perhaps I'm going about this all wrong?
>
> James
>
>
>
>
> On 12/13/06, Bob Arnott <[EMAIL PROTECTED]> wrote:
>> James A. Cubeta wrote:
>>
>> [snipped...]
>>
>> > So my questions revolve around tweaking this framework for speed. I
>> > guess my very first question is: Is there a way to instruct DBCP to
>> > initially set up a some number of connections?
>>
>> When you create your pool with BasicDataSource, you can modify its
>> behavior
>> with it's properties. One of them is initialSize -
>>
>> http://jakarta.apache.org/commons/dbcp/apidocs/org/apache/commons/dbcp/BasicDataSource.html#initialSize
>>
>> Perhaps this will supply the functionality you are looking for...?
>>
>> Cheers,
>>
>> --
>> Bob Arnott
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
> --
> James A. Cubeta
> 703.624.5689 (c) / 571.223.3368 (w)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
  public static DataSource setupDataSource() {

      //New stuff
      Properties dataSourceProperties = new Properties();
      dataSourceProperties.setProperty("factory", 
"org.apache.commons.dbcp.BasicDataSourceFactory");
      dataSourceProperties.setProperty("driverClassName", 
"oracle.jdbc.driver.OracleDriver");
      dataSourceProperties.setProperty("url", 
"jdbc:oracle:thin:@server.domain.com:1521:DEV");      
      dataSourceProperties.setProperty("username", "guest");
      dataSourceProperties.setProperty("password", "guest");
      dataSourceProperties.setProperty("minIdle", "3");
      dataSourceProperties.setProperty("maxIdle", "8");
      dataSourceProperties.setProperty("maxActive", "5");
      dataSourceProperties.setProperty("maxWait", "20000");
      dataSourceProperties.setProperty("removeAbandoned", "true");
      dataSourceProperties.setProperty("logAbandoned", "false");
      dataSourceProperties.setProperty("removeAbandonedTimeout", "5");

      DataSource dataSource = null;
      try {
        dataSource = 
BasicDataSourceFactory.createDataSource(dataSourceProperties);
      } catch (Exception e) {
          e.printStackTrace();
      }
      return dataSource;
  }
  
  public boolean setConnection() {
      System.out.println("Loading underlying JDBC driver.");
      try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
          return false;
      }


      DataSource dataSource = setupDataSource();

      try {
                conn = dataSource.getConnection();
                } catch (SQLException e) {
                        e.printStackTrace();
                        return false;
                }
                
                return true;
        
  } 

  public void init() {
          // Initialize logger
          logger = Logger.getLogger(GeoController.class);
          logger.info(this.getClass().getName() + " - initialized.");
          // Initialize connection pool
          this.setConnection();
  }
  
  public void destroy() {
          try { conn.close(); } catch(Exception e) { }
  }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to