Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D731E63285F for ; Mon, 14 Dec 2009 10:53:52 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 05175-06 for ; Mon, 14 Dec 2009 14:53:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mta1.zcs.ext.wpsrv.net (mta1.zcs.ext.wpsrv.net [78.47.55.244]) by mail.postgresql.org (Postfix) with ESMTP id 1990462DB89 for ; Mon, 14 Dec 2009 10:53:41 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id 679CD180BD; Mon, 14 Dec 2009 15:53:39 +0100 (CET) X-Virus-Scanned: amavisd-new at mta1.zcs.ext.wpsrv.net Received: from mta1.zcs.ext.wpsrv.net ([127.0.0.1]) by localhost (mta1.zcs.ext.wpsrv.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id K5-miXHI9bjw; Mon, 14 Dec 2009 15:53:38 +0100 (CET) Received: from store1.zcs.ext.wpsrv.net (store1.zcs.ext.wpsrv.net [78.47.55.243]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id E49CD1808C; Mon, 14 Dec 2009 15:53:38 +0100 (CET) Date: Mon, 14 Dec 2009 15:53:38 +0100 (CET) From: Andreas To: Craig Ringer Cc: pgsql-jdbc@postgresql.org Message-ID: <26903539.10.1260802418802.JavaMail.root@store1.zcs.ext.wpsrv.net> In-Reply-To: <9840044.8.1260802397210.JavaMail.root@store1.zcs.ext.wpsrv.net> Subject: Re: keeping Connection alive MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Mailer: Zimbra 6.0.2_GA_1912.DEBIAN4.0 (ZimbraWebClient - FF3.0 (Linux)/6.0.2_GA_1912.DEBIAN4.0) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/40 X-Sequence-Number: 20121 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