[concurrency-interest] Cancellation convention

Mike Quilleash mike.quilleash at azuresolutions.com
Wed Jun 7 03:14:07 EDT 2006

Thanks for your replies guys.

My problem isn't really a timeout problem it's a user cancellation
problem.  Some of our queries can be extremely long running
(minutes-hours) and it would be nice for the user to be able to cancel
them mid-process for whatever reason, they might spot a problem in the
configuration etc.

The problem is when the execution goes into either
PreparedStatement.executeQuery/executeUpdate.  Both of these are
blocking until some rows are available or the update has completed,
respectively.  For a query involving group by/order by executeQuery
can't return until all the aggregation and ordering logic has been done
in the database.

During this potentially-prolonged period the user would like to cancel
the execution, which would involve calling PreparedStatement.cancel.  I
have tested this between two threads, one executing the other calling
cancel, with a limited number of JDBC drivers (jtds for SQLServer and
Oracle's own driver) and it seems to work ok.

The issue is slightly compounded by the query could be one of several
that executes in sequence which I may want to cancel at any time.  I
could just add cancel hooks at each "depth" of my libraries down to the
JDBC level so if a user cancels the overall process it would work it's
way down through the executing process until the current JDBC call gets
cancelled.  I just wondered if there was a more elegant/preferred way of
doing it using interrupt().  I am mildly concerned that it could
interrupt nio channel traffic and close the channel as a consequence but
assuming I can avoid that is this a sensible approach?



-----Original Message-----
From: Dhanji R. Prasanna [mailto:dhanji at gmail.com] 
Sent: 07 June 2006 01:17
To: Mike Quilleash
Cc: concurrency-interest at cs.oswego.edu
Subject: Re: [concurrency-interest] Cancellation convention

On 6/7/06, Mike Quilleash <mike.quilleash at azuresolutions.com> wrote:

> Specifically I'm interested in being able to cancel long running JDBC 
> calls (using PreparedStatement.cancel()).

JDBC provides a setQueryTimeout which will throw a SQLException if the
PS runs past the timeout limit?
This should be the preferred way of timing out long-running queries, as
the semantics of concurrency with JDBC are obscure at best--unless Im
very much mistaken and have misunderstood your problem.

This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 

More information about the Concurrency-interest mailing list