Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-05-03
4
Medium Priority
?
289 Views
Last Modified: 2010-04-17
Hi All,
Can I make the method getting the connection from connection pool  Synchronize?

Plz let me know

Thanks
0
Comment
Question by:hkishoreb
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
WelkinMaze earned 1500 total points
ID: 16598889
Hi,
Yes you can make such method synchronized.
0
 

Author Comment

by:hkishoreb
ID: 16599184
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
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16599211
what do you mean by hanging up?
0
 

Author Comment

by:hkishoreb
ID: 16760806
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Screencast - Getting to Know the Pipeline

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question