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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.
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.