max connections
max connections
От:
"Simon Stanlake" <stanlake@hi.ca>
Дата:
Hi, The documentation states that the Connection object is thread-safe... I took this to mean I can create a connection as a singleton and pass it out to all my threads with no worries. When I did this I noticed that a SimpleObjectPool was being created, and I would occasionally get a "max connections exceeded" error from the database. I assume this means the implementation actually creates a connection pool and passes connections out to threads as needed. My question is... what is the proper way to handle postgres connections in a multithreaded environment? is it OK to create a singleton of the connection? if so, is there a way to limit the number of connections the pool makes to the database so that the maximum is not exceeded? _______________________________ Simon Stanlake Harmony Integrated Systems Inc. http://www.hi.ca
Re: max connections
От:
Rene Pijlman <rene@lab.applinet.nl>
Дата:
On Wed, 29 Aug 2001 14:38:21 -0700, you wrote: >My question is... what is the proper way to handle postgres connections in >a multithreaded environment? See http://www.postgresql.org/users-lounge/docs/7.1/programmer/jdbc-thread.html >is it OK to create a singleton of the connection? "If a thread attempts to use the connection while another one is using it, it will wait until the other thread has finished its current operation. ... This is fine for applications and applets but can cause a performance problem with servlets. With servlets you can have a heavy load on the connection. If you have several threads performing queries then each but one will pause, which may not be what you are after." >if so, is there a way to limit the number of connections the >pool makes to the database so that the maximum is not exceeded? I'm not sure what you mean by that. If you create a singleton I'd say there is exactly one connection. Regards, René Pijlman