Re: keeping Connection alive

From: Andreas <ml(at)3(dot)141592654(dot)de>
To: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: keeping Connection alive
Date: 2009-12-14 14:53:38
Message-ID: 26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hi Craig,

thanks a lot for your detailed answer! I learned a lot and hopefully are going to do a better design next time. :)

> Is its connection to the server diect via a local Ethernet segment? Or
> is it going through routers - possibly routers doing NAT, such as most
> home user modem/routers?

Neither local nor NAT/home routers.

> > So one approach may be to implement a DataSource which does check
> (i.e. "SELECT 1") validity before returning the Connection (and
> reconnect if its not valid, i.e. throwing a SQLException?).
>
> Nononono....
>
> Have the DataSource _consumer_ deal with it.
>
>
> int retries = MAX_RETRIES;
> do {
> try {
> try {
> Connection conn = myprovider.getConnection();
> // do work
> break;
> } finally {
> try {
> stmt.close();
> } catch (SQLException e) {
> // log to complain about statement close failure
> }
> }
> } catch (SQLException e) {
> myProvider.invalidateConnection(conn, e);
> retries--;
> }
> } while (retries > 0);
>
>
> ... where "invalidateConnection(Connection, Throwable)" tells the
> provider/pool that the connection is broken.

I'm not sure how to do this, because AFAIK a DataSource implementation does not have a method for invalidating the Connection. How to do this when implementing against standard interfaces?

Thanks again for your detailed answer!

Best regards,
Andreas

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Craig Ringer 2009-12-15 01:57:53 Re: keeping Connection alive
Previous Message Petr Jelinek 2009-12-14 13:15:38 Re: Hstore PGObject class