View Single Post
Old 05-19-2004, 02:59 AM   #12 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Hmmm, looking this over, I think I see a problem. You have the right idea when declaring "ds" and "pool" static; you only want one pool. But, look at how you're getting it. According to your code, you need to say
Code:
  as400 pool = new as400();
  Connection conn = pool.getConnection();
Now, ignoring for the moment the fact that should say AS400 instead of as400, what happens is because you're calling the constructor you're creating a new pool each time. Quite frankly, I'm amazed you're only having overhead issues, I thought that would have caused some concurrency issues.

Here's how you need to rewrite your pool:
Code:
private static AS400JDBCConnectionPoolDataSource ds;
private static javax.sql.PooledConnection pool;
// private Connection con; - You don't need this here.

//  public AS400(){} You don't need a constructor for this class.

  static private void init() throws SQLException {
    if(pool == null){
      ds = new AS400JDBCConnectionPoolDataSource("10.10.10.1","USER", "PASS");
      ds.setLibraries("RC1380BFR1");
      ds.setDateFormat("iso");
          
      pool = ds.getPooledConnection();
    }
  }

  static public Connection getConnection() throws SQLException{
    init();
    return pool.getConnection();
  }
I decided to throw the SQLExceptions, you can catch them if you'd like. Do you have an online API for this pool? I find it odd that they call the method to get the pool, getPooledConnection(), as opposed to getPool() or something like that.
__________________
GitS
Belisarius is offline   Reply With Quote