Synchronization and Connection pool ---- saw some time delays
Posted on 2006-05-25
Here is the more description abouit the problem.
I made the method that is getting the DataSource from the JNDI context as Synchronized. Max pool capacity as 20.
This is working fine if the load is less on the server. But at the Peak load all the connections are busy and Server is trying to create more pooled connections. At this point because of the Synchronized method in getting the connections We are seeing slow responce (time delays) in getting the connections from newly created pool . Here is the code that put in the get connection method.
public synchronized static final Connection getConnection(int iWhichConnectionPool)
// create instance of Weblogic's JDBC pool driver
java.sql.Connection conn = null;
Context ctx = null;
// extra check in case this static class was garbage collected
if ((m_aNumOpenConnections == null) || (m_aConnectionPoolNames == null))
Properties env = new Properties();
String url = System.getProperty("url");
ctx = (Context) new InitialContext(env);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/dataSrc");
conn = ds.getConnection();
catch (Exception e)
Log.write("DatabaseManager.getConnection(int): " + e.getMessage());
conn = null;
m_aNumOpenConnections[iWhichConnectionPool] ++; // increment open connections counter
Log.write("Opened " + m_aConnectionPoolNames[iWhichConnectionPool] + " database connection. "
+ m_aNumOpenConnections[iWhichConnectionPool] + " "
+ m_aConnectionPoolNames[iWhichConnectionPool]+ " connections now open.");
}// end getConnection()
Can i make this method non synchronize.
Please elt me know the solution.