DBCP Connection Pooling
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   joj_mathews
Posted On:   Thursday, October 30, 2003 11:36 PM

hi, I have implemented connection pooling for postgres database on tomcat 4.1.24. I am using DBCP and have used the "removeAbandoned" parameter of the DBCP. Everything is fine but I have a doubt which needs to be clarified before implementing it for the production. For testing I've directly written the following codes in the Data Access Objects. Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource)envContext.lookup("jdbc/postgres"); Connection conn = ds.getConnection(); In the tomcat JNDI-datasource reference page, for "Random Connection Closed Exceptions", it   More>>
			
hi,

I have implemented connection pooling for postgres database on tomcat 4.1.24. I am

using DBCP and have used the "removeAbandoned" parameter of the DBCP. Everything is

fine but I have a doubt which needs to be clarified before implementing it for the

production.

For testing I've directly written the following codes in the Data Access Objects.

Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/postgres");
Connection conn = ds.getConnection();

In the tomcat JNDI-datasource reference page, for "Random Connection Closed

Exceptions", it is recommended to use the following lines.

conn.close(); // Return to connection pool
conn = null; // Make sure we don't close it twice


MY QUESTION

1.Is it wise to create a common "dbconnector" object and use the methods of it to open

and close the connection,by passing the connection object as shown below for implementing the above codes.

2. If yes, is it nessecary to make the dbconnector class multithreaded.?

// the DBConnector class

public class DBConnector {

public void openConnection(Connection conObj){
try{
if(conObj!=null){
if(ctx == null )throw new Exception("Boom - No Context");
DataSource ds =(DataSource)ctx.lookup("java:comp/env/jdbc/postgres");
if (ds != null) {
conObj = ds.getConnection();
}
}
}catch(Exception e){
e.printStackTrace();
} //end of open connection



public void closeConnection(Connection conObj){
if(conObj != null){
conObj.close();
conObj=null;
}
} //end of close connection

}// end of DBConnector



Thanks in advance for your replies,


Joj Mathews
   <<Less
About | Sitemap | Contact