Skip site navigation (1) Skip section navigation (2)

Re: Hibernate / other ORM and pg_advisory_lock

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: pgsql-jdbc(at)postgresql(dot)org
Cc: Andrew <archa(at)pacific(dot)net(dot)au>
Subject: Re: Hibernate / other ORM and pg_advisory_lock
Date: 2008-04-07 06:30:06
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
Peter Kovacs wrote:
>> -First: thankfully polling is not required. One of the nice things about pg's advisory locks is
>> the ability for the client to block on a lock. If the app wants to wait on an advisory lock all it
>> has to do is attempt to acquire the lock; the thread will block until a result is returned (ie the
>> lock is obtained).
>> If the user gets bored of waiting the UI thread can just signal the blocked DB thread to abort
>> the query and get on with something else.
> Is this mechanism supported by the PostgreSQL JDBC driver?

Good question. The answer is yes, as shown by the attached test class,
but it's definitely a good idea to test rather than assume these things.
The test should be run while some other job, like a psql interactive
session, holds pg_advisory_lock(1). You'd need to update the connection
string to use it.

Canceling the query works fine, at least on 8.3 with the JDBC4 8.3
driver. The JDBC driver handles the cancel() call by establishing a new
connection and issuing a cancel query request with it.

Of course, I can't guarantee that the JDBC driver isn't polling
internally, but it's not hitting the database to do it so for my use I
don't much care. According to wireshark there's no traffic on port 5432
during the 10 second wait interval. I'd be surprised if it wasn't
actually blocked on the network read, though I haven't gone digging to
verify this.

Craig Ringer

Description: text/x-java (2.0 KB)

In response to

pgsql-jdbc by date

Next:From: AndrewDate: 2008-04-07 06:48:29
Subject: Re: Hibernate / other ORM and pg_advisory_lock
Previous:From: AndrewDate: 2008-04-07 06:24:52
Subject: Re: Hibernate / other ORM and pg_advisory_lock

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group