Sun WebServer 6.1 SP4 Connection Pool

Hi All,

I need your help, we are trying to implement server's connection pool and the way we are doing is we made one separate java class that gives the connection and close the connection. This class has a method getConnection() and where ever in application we need connection we use this moethod.

public static synchronized Connection getConnection()

{

InitialContext ctx= new InitialContext();

String dsName = "java:comp/env/jdbc/jdbc-empl";

DataSourceds= (javax.sql.DataSource) ctx.lookup(dsName);

conn = ds.getConnection();

return conn;

}

My question is do I need to make this method synchronized? Please help.

Thanks

Message was edited by:

bplboy..

[742 byte] By [bplboy..a] at [2007-11-26 22:07:53]
# 1

That depends. Is the connection pool you're using inherently thread-safe? Check the vendor docs.

Also, you will be generating quite a bit of overhead in establishing an initialContext and looking up your datasource with every connection you request. These values should probably be cached.

bckrispia at 2007-7-10 10:53:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
I am using Sun One WebServer 6.1 SP4, do u have any idea if that's thread safe?Thanks
bplboy..a at 2007-7-10 10:53:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Like I said, check the documentation on your server's Connection Pool
bckrispia at 2007-7-10 10:53:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...