Hello all,

I would like to get feedback on my design for a servlet that is required to
search a db2 database for employees (Yes! the Sample Db!).

The Servlet is configured as follows:

servlet class{

//instance var
javax.sql.DataSource ds = null;

init(){

//get datasource connection from WebSphere 3.5 (JDBC 2).
ds = ........

}//end init

doPost(...){

//get a connection from the connection pool
Connection conn = ds.getConnection(user, password);

//do something then close connection

}//end doPost.

1. The servlet first establishes a datasource handle to WebSphere's
connection pool for this database. This is required only once and seemed
like a good idea to place in the init method.

2. For each request (thread) doPost is called and a connection object to the
database is obtained. The question I have is should the getConnection method
call be in a synchronized block such as:

synchronized(objLock){

        Connection conn = ds.getConnection(user, password);

}//end sync block

I think it should not since the connection object (conn) is declared within
the method (thus locale and thread safe) and the getConnection method is
returning a common connection object.

Thoughts and comments please!

Best Regards


Marc

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to