Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D62DC632A8A for ; Sun, 18 Jul 2010 23:09:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 68876-10 for ; Mon, 19 Jul 2010 02:09:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id A079E6329A9 for ; Sun, 18 Jul 2010 23:09:08 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 6A3D579119; Mon, 19 Jul 2010 10:09:05 +0800 (WST) Received: from localhost (localhost [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 10278AE5B4; Mon, 19 Jul 2010 10:06:32 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (mail.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id wVwSMH-oIFRa; Mon, 19 Jul 2010 10:06:26 +0800 (WST) Received: from [10.1.1.6] (124-168-255-56.dyn.iinet.net.au [124.168.255.56]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id 8577FAE4AB; Mon, 19 Jul 2010 10:06:26 +0800 (WST) Message-ID: <4C43B3BC.40609@postnewspapers.com.au> Date: Mon, 19 Jul 2010 10:09:00 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Lightning/1.0b1 Thunderbird/3.0.4 MIME-Version: 1.0 To: max CC: pgsql-jdbc@postgresql.org Subject: Re: Questions about Listen/Notify mechanism References: <4C4267FA.2080604@directbox.com> In-Reply-To: <4C4267FA.2080604@directbox.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/49 X-Sequence-Number: 20714 On 18/07/10 10:33, max wrote: > "A key limitation of the JDBC driver is that it cannot receive > asynchronous notifications and must poll the backend to check if any > notifications were issued." > > Does that mean that the driver will poll the database, e.g. every 5 > seconds? The driver never will, but your app might have to in order to receive notifications. What happens is that notifications are processed whenever any other I/O to the database is done. If you need to poll for notifications you can send a dummy statement. If you're not using SSL you can actually use the PgConnection's methods to check for new notifications without any network I/O. This won't work with SSL connections, though, because there's no reliable way to check to see if there are application stream bytes availible to read in from ssl connection. I've written some utility code for this - a class that will maintain the LISTEN list on a connection, restore it if the connection is broken and re-established, and poll for notifications. It'll avoid network polling unless it suspects the connection might be using ssl. I need to clean it up a bit for public use, though, as it's currently tied to my app's Hibernate connection provider, which is a custom one designed to maintain only one connection and let the listen/notify poller use it when the app isn't busy with it. > If so, that would not be acceptable for me, because that is > exactly what I want to avoid. The only advantage of using Listen/Notify > in that case would be that I don't need an extra notification table that > my trigger would fill. Am I wrong? Oo It's a *LOT* cheaper than polling a table's contents, and you can avoid network polling if you're not using SSL. -- Craig Ringer