Re: "persistent" connection in a Servlet

From: Ned Wolpert <ned(dot)wolpert(at)knowledgenet(dot)com>
To: Nikola Milutinovic <Nikola(dot)Milutinovic(at)ev(dot)co(dot)yu>
Cc: PostgreSQL JDBC <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: "persistent" connection in a Servlet
Date: 2002-01-02 16:10:02
Message-ID: 1009987802.5508.33.camel@osti.knowledgenet.corp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 is loaded. 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 reconnect or 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(dot)wolpert(at)knowledgenet(dot)com>

D08C2F45: 28E7 56CB 58AC C622 5A51 3C42 8B2B 2739 D08C 2F45

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Ned Wolpert 2002-01-02 16:59:37 Re: Submittal for JDBC Pooling driver (For 7.3)
Previous Message Kovács Péter 2002-01-02 16:04:39 Re: Submittal for JDBC Pooling driver (For 7.3)