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: | 47F9BF6E.107@postnewspapers.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
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
Attachment | Content-Type | Size |
---|---|---|
JdbcCancelTest.java | text/x-java | 2.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew | 2008-04-07 06:48:29 | Re: Hibernate / other ORM and pg_advisory_lock |
Previous Message | Andrew | 2008-04-07 06:24:52 | Re: Hibernate / other ORM and pg_advisory_lock |