Re: PGConnection.getNotifications(0) doesn't block - Mailing list pgsql-jdbc

From Pawel Veselov
Subject Re: PGConnection.getNotifications(0) doesn't block
Date
Msg-id CAMnJ+BdtQBsZFqD93R4g+rx+28htsZ6uRBe6umPagi2JzuGR=A@mail.gmail.com
Whole thread Raw
In response to Re: PGConnection.getNotifications(0) doesn't block  (rob stone <floriparob@tpg.com.au>)
List pgsql-jdbc
> > I'm implementing a bit that is expected to wait for published channel
> > notifications,
> > and once there are any - process them.
> >
> > I'm using PGConnection.getNotifications(0), but that immediately
> > returns an empty
> > array, and doesn't block like JavaDoc says it should.
> >
> > I'm on 42.6.0.
> >
> > What am I missing?
> >
> > Thank you.
> Have you read the JDBC docs
> https://jdbc.postgresql.org/documentation/server-prepare
> which has a section about Listen/Notify?

I've read https://access.crunchydata.com/documentation/pgjdbc/42.1.1/listennotify.html
instead. I've read the Listen/Notify section in
https://jdbc.postgresql.org/documentation/server-prepare just now,
which carries identical text. I've also read the JavaDocs for the method(s).

All these sources agree or at least don't contradict that
getNotifications(0) should block without conditions,
and none mention that the connection must be in the IDLE
transaction state.

For that matter, even
https://www.postgresql.org/docs/current/sql-listen.html doesn't say
anything about the fact that notifications are only received/can be
read if the connection is in that state. It only mentions that the
 transaction that executed LISTEN must be first
committed for that connection to start seeing notifications (for
subscribed channel).

What I was effectively doing on that connection is:
BEGIN
LISTEN
COMMIT
BEGIN
UPDATE xxx;
<poll for notifications>

I've created this for tracking: https://github.com/pgjdbc/pgjdbc/issues/2937



pgsql-jdbc by date:

Previous
From: rob stone
Date:
Subject: Re: PGConnection.getNotifications(0) doesn't block
Next
From: ihab sabiq
Date:
Subject: PrepareStatement and parameters data types