Menu

Is synchronized on getConnection correct?

Help
Glen
2005-10-08
2013-04-25
  • Glen

    Glen - 2005-10-08

    Hi,

    I have a multithreaded program that has been locking up because one of the threads is blocking in getConnection waiting for a free connection and all of the other threads are unable to call releaseConnection as both getConnection and releaseConnection are marked as synchronized.

    Has anyone else had this problem?

    Thanks,
    Glen.

     
    • nr

      nr - 2005-10-10

      Hi,

      Thanks for this feedback.
      Your datasource is probably blocking on ds.getConnection() and you're right in that case this prevent other threads from releasing their connection. What a shame :)
      Indeed, synchronized seems not appropriate for these 2 methods (can't remember why we sync them!)
      Have you tried without ? (just a matter of modifying the manager template).
      Thanks again

      Nicolas.

       
    • Glen

      Glen - 2005-10-11

      Hi Nicolas,

      Yes my datasource does block on ds.getConnection when all the connections are in use because I am using a fixed size connection pool.  I have removed the synchronized from the getConnection and releaseConnection and this works to me.  I believe the synchronized tags are on those methods for handling a multithread application calling beginTransaction and endTransaction.  If you were to use synchronized (trans_conn) blocks in beginTransaction, endTransaction, getConnection, and releaseConnection this should do the trick.  My application doesn't use transactions so I can really test these changes.

      Thanks,
      Glen.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.