Re: "persistent" connection in a Servlet
От | Ned Wolpert |
---|---|
Тема | Re: "persistent" connection in a Servlet |
Дата | |
Msg-id | 1009987802.5508.33.camel@osti.knowledgenet.corp обсуждение исходный текст |
Ответ на | "persistent" connection in a Servlet ("Nikola Milutinovic" <Nikola.Milutinovic@ev.co.yu>) |
Список | pgsql-jdbc |
Well, you'll have problems if you re-use the same connection if multiple servlet requests are being handled at the same time. Each request runs in its own thread, and the servlet variables are shared, which means the connection is shared. A JDBC connection can only handle one request at a time. Possible solutions are 1) Make the thread synchronized so only one request can process at a time. This isn't good since it slows up big time for multiple threads. 2) Use a pooling manager to pool requests. (Like poolman from www.codestudio.com) This way, you can allocate a fixed number of jdbc connections and keep them initialized, rather than having to re-create them. Either way, if you shut down the database on an open connection, it will invalidate the connection. (SideNote, you need to shutdown the database using the '-m fast' option since the regular option will wait until all the connections are closed) The connection will need to be re-established. (Poolman can do this automatically, the jdbc driver does not itself.) On Fri, 2001-12-28 at 03:02, Nikola Milutinovic wrote: > Hi all. > > One question. Suppose I write a servlet which uses one JDBC connection, initializing it not per-request, but once it isloaded. Similarly it closes the connection not after the request has been serviced, but only when the servlet is unloaded.This means that JDBC connection will be opened and held open for a long time, with sporadic interactions. > > What happens if I shutdown the database, while JDBC connection is open and bring it up again? Will it try to reconnector do I have to check for status? > > Nix. > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org -- Virtually, Ned Wolpert <ned.wolpert@knowledgenet.com> D08C2F45: 28E7 56CB 58AC C622 5A51 3C42 8B2B 2739 D08C 2F45
Вложения
В списке pgsql-jdbc по дате отправления: