pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas <ml@3.141592654.de>
To: Craig Ringer <craig@postnewspapers.com.au>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: keeping Connection alive
Date: Mon, 14 Dec 2009 15:53:38 +0100 (CET)
Message-ID: <26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net> (raw)
In-Reply-To: <9840044.8.1260802397210.JavaMail.root@store1.zcs.ext.wpsrv.net>

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



view thread (12+ messages)  latest in thread

Message-ID: <26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net>
Permalink:  ../26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net/
Also on:    postgresql.org/message-id/26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: ml@3.141592654.de, craig@postnewspapers.com.au
  Subject: Re: keeping Connection alive
  In-Reply-To: <26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net>
  References: <9840044.8.1260802397210.JavaMail.root@store1.zcs.ext.wpsrv.net> <26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox