From: Andres Olarte <olarte.andres@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Problem with Async (multiple) notifications
Date: Fri, 24 Jun 2005 17:39:54 -0600
Message-ID: <3fccaa6905062416392e578f58@mail.gmail.com> (raw)
I've been playing with async notifications lately, and I've found a
small problem: when several notifications are issued at once (for
example within a transaction) normally only one of those gets to the
client. The rest of the notifications are not received until
something happens on the connection, for example a query or another
notification. I'm using the latest CVS, updated yesterday. I've
looked over the code, and there's nothing obvious. I think that this
has to do with java's handling of sockets, as the C example that deals
with notifications works fine. It seems that some packages are
"stuck" in the socket, but my knowledge of sockets is very limited. A
possible workarround would be to issue the simplest possible query or
message to the backend when a notification is found, to see if anymore
notifications are "stuck". This would generate a little bit of extra
traffic, but only when there is a notification. Here is a small test
case showing what's happening:
public class TestAsync extends TestCase {
Connection conn2,conn1;
public void testAsync() {
String user = "andres";
String pass = "";
String url = "jdbc:postgresql://127.0.0.1/template1";
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException cnf) {
fail("Data Base Driver not Found: " + cnf.getMessage());
}
try {
conn1 = DriverManager.getConnection(url, user, pass);
conn2 = DriverManager.getConnection(url, user, pass);
conn2.setAutoCommit(true);
Statement stmt2 = conn2.createStatement();
stmt2.execute("LISTEN test1");
stmt2.execute("LISTEN test2");
stmt2.execute("LISTEN test3");
PGConnection pgconn = (PGConnection) conn2;
Statement stmt1=conn1.createStatement();
stmt1.execute("NOTIFY test1;");
stmt1.execute("NOTIFY test2;");
stmt1.execute("NOTIFY test3;");
conn1.commit();
PGNotification[] nots = pgconn.getNotifications();
assertEquals(3,nots.length);
} catch (SQLException sqle) {
fail("SQLException sql" + sqle.getLocalizedMessage());
}
}
I'm running a 7.4 backend, but I don't think that's the problem. But
if someone thinks I'm doing something wrong, please let me know!!
thanks to all of the people that have worked on PostreSQL
Andres Olarte
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: olarte.andres@gmail.com
Subject: Re: Problem with Async (multiple) notifications
In-Reply-To: <3fccaa6905062416392e578f58@mail.gmail.com>
References: <3fccaa6905062416392e578f58@mail.gmail.com>
* 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