Can I make the method getting the connection from connection pool Synchronize

Hi All,
Can I make the method getting the connection from connection pool  Synchronize?

Plz let me know

Thanks
hkishorebAsked:
Who is Participating?
 
WelkinMazeConnect With a Mentor Commented:
Hi,
Yes you can make such method synchronized.
0
 
hkishorebAuthor Commented:
But my problem here is the server is hanging up  when the load is high on it.  What is the solution to avoid that kind of hang ups

Thank you
0
 
WelkinMazeCommented:
what do you mean by hanging up?
0
 
hkishorebAuthor Commented:
Sorry for the late reply.

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)
                                                          throws Exception
      {
           // create instance of Weblogic's JDBC pool driver
           Log.write("DatabaseManager.getConnection(int): BEGIN");
        
           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))
         {
            loadArrays();
         }

       Properties env = new Properties();
       String propsFilePath=System.getProperty("propfile");
       String url = System.getProperty("url");
       env.put(Context.PROVIDER_URL, url);
       env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");


           try
           {
            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.");

         return conn;

        }// end getConnection()

Can i make this method non synchronize.

Please elt me know the solution.

Thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.