From: Kris Jurka <books@ejurka.com>
To: Michael Barker <mike@middlesoft.co.uk>
Cc: pgsql-jdbc@postgresql.org
Cc: Andy Oliver <acoliver@jboss.org>
Subject: Re: [PATCH] Support for ping method.
Date: Mon, 17 Apr 2006 02:49:12 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0604170237370.30846@leary2.csoft.net> (raw)
In-Reply-To: <Pine.BSO.4.63.0604170115380.17202@leary2.csoft.net>
References: <1144305529.2955.11.camel@corona>
<Pine.BSO.4.63.0604170115380.17202@leary2.csoft.net>
> On Thu, 6 Apr 2006, Michael Barker wrote:
>
>> Attached is a patch that adds support for a ping method on the
>> AbstractJdbc2Connection. This is useful for JBoss (and other
>> containers) where the container needs to check if the connection is
>> alive before passing it to the caller. Currently JBoss does a "SELECT
>> 1", but using the new ping method there is a boost in performance.
>> Opening and closing 1000 connections from a datasource:
>>
>
> There are a number of problems with this patch. In no particular order...
>
6) I'm not sure what guarantees ping is trying to make. Is it solely
to ensure that the backend is still connected or is it to ensure that the
connection state is ready to receive new commands. Consider the
following as the attached test case demonstrates:
conn.setAutoCommit(false);
conn.createStatement().execute("SELECT 1/0"); // Forces transaction abort
conn.ping(); // Returns 0 saying connection is "good".
conn.createStatement().execute("SELECT 1"); // Fails b/c in aborted txn.
If you need the stronger guarantee of transaction state validity then I
think you could try the V2 EmptyQuery attempt on the V3 protocol as well.
When JDK1.6 comes out I imagine that this will be replaced by the
Connection.isValid method which does not seem to require anything
beyond a current backend connection.
http://download.java.net/jdk6/docs/api/java/sql/Connection.html#isValid(int)
Kris Jurka
Attachments:PingTest.java (text/plain, 564B) download
import java.sql.*;
public class PingTest {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5820/jurka","jurka","");
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
try {
stmt.execute("SELECT 1/0");
} catch (SQLException sqle) {
sqle.printStackTrace();
}
System.out.println(((org.postgresql.jdbc2.AbstractJdbc2Connection)conn).ping());
stmt.execute("SELECT 1");
}
}
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: books@ejurka.com, mike@middlesoft.co.uk, acoliver@jboss.org
Subject: Re: [PATCH] Support for ping method.
In-Reply-To: <Pine.BSO.4.63.0604170237370.30846@leary2.csoft.net>
References: <1144305529.2955.11.camel@corona> <Pine.BSO.4.63.0604170115380.17202@leary2.csoft.net> <Pine.BSO.4.63.0604170237370.30846@leary2.csoft.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