Re: setQueryTimeOut - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: setQueryTimeOut
Date
Msg-id Pine.BSO.4.56.0410291812150.16598@leary.csoft.net
Whole thread Raw
List pgsql-jdbc

On Wed, 27 Oct 2004, Oezcan Acar wrote:

> do you now something new about the implementation of
> Statement.setQueryTimeOut ? As far as I now this method is not
> implemented in the current driver. Do you know, how to implement such a
> method? Thank you.
>

There are two ways to approach this problem.  With the backend's
statement_timeout config variable and the driver's Statement.cancel()
method.  The issue with both of these is that you need to be concerned
about thread safety and only cancelling the correct statement.

Using the backend's statement_timeout is pretty straightforward, before
each query set it and after each query reset it.  Issues to be careful of
are making sure the timeout gets reset on errors.  I would also be
concerned about the potential overhead of issuing two additional queries
for each user level statement execution.

With the Statement.cancel approach you would create a new thread to wake
up and issue the cancel if the statement hasn't completed yet, but I
believe there are some race conditions that make it difficult to do this
correctly:

http://archives.postgresql.org/pgsql-jdbc/2003-11/msg00148.php
http://archives.postgresql.org/pgsql-jdbc/2003-09/msg00175.php

Kris Jurka

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: ps.setCharacterStream() and memory usage
Next
From: Kris Jurka
Date:
Subject: Re: PGobject overhaul (was Re: tightening up on use of oid