[concurrency-interest] Cancellation convention

Tim Peierls tim at peierls.net
Tue Jun 6 15:05:15 EDT 2006

Is it safe to share PreparedStatement instances between threads? If not,
then there's nothing you can do, since you can't have one thread in
PreparedStatement.execute() and another in PreparedStatement.cancel().

If you can guarantee thread-safety of PreparedStatement, then you can use a
technique described in Section 7.1.6 of Java Concurrency in Practice: Create
a Thread with a custom interruption policy by overriding interrupt() to call
PreparedStatement.cancel() in addition to super.interrupt () -- be sure to
use a finally block for the latter. (Even better would be to use the
CancellableTask technique in Section 7.1.7; the particular implementation
described there relies on a feature only available in Java 6, but you can
work around that.)


On 6/6/06, Mike Quilleash < mike.quilleash at azuresolutions.com> wrote:
>  Quick question about cancelling things and the usual way of doing it.
> Is it the convention to use Thread.interrupt() to do cancellation of a
> task in another thread?  Presumably the Thread being run must either be
> calling API code that is interruptible or check itself for the interrupted
> state regularly.
> Specifically I'm interested in being able to cancel long running JDBC
> calls (using PreparedStatement.cancel()).  Would a sensible way be to fork
> off the PreparedStatement execution in another thread and have the main
> thread wait for the second thread to complete, but if it is interrupted then
> call the PreparedStatement.cancel() and throw an exception out to indicate
> the cancellation succeeded?  Just after some best practice advice.
> Cheers.
> Mike.
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20060606/18cc76c4/attachment.html 

More information about the Concurrency-interest mailing list