Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 89E9D634523 for ; Thu, 29 Oct 2009 11:20:32 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 47095-08 for ; Thu, 29 Oct 2009 14:20:24 +0000 (UTC) X-Greylist: delayed 00:20:23.81267 by SQLgrey-1.7.6 Received: from melbourne.micfo.com (melbourne.micfo.com [115.124.106.27]) by mail.postgresql.org (Postfix) with ESMTP id BE6006343EA for ; Thu, 29 Oct 2009 11:20:24 -0300 (ADT) Received: from 87-204-194-135.dg-net.pl ([87.204.194.135]:37604 helo=radek.localnet) by melbourne.micfo.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1N3VrT-0000FF-50 for pgsql-jdbc@postgresql.org; Thu, 29 Oct 2009 10:20:23 -0400 To: pgsql-jdbc@postgresql.org Subject: Implementation of query timeout From: =?utf-8?q?Rados=C5=82aw_Smogura?= Date: Thu, 29 Oct 2009 15:19:58 +0100 MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <200910291519.58180.rsmogura@softperience.eu> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - melbourne.micfo.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - softperience.eu X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.98 tagged_above=-10 required=5 tests=BAYES_00=-2.599, RCVD_IN_SORBS_WEB=0.619 X-Spam-Level: X-Archive-Number: 200910/42 X-Sequence-Number: 20044 Hello, I send this message again, because there were problems with my email address, so it didn't reach mailinglist. I read a TODO list, and I decided to help a bit. So I've tried to implement queryTimeout, currently ony for non-batch statements. You can see code, at http://rsmogura.net/pgsql/pgsql_jdbc_querytimeout.tar.bz2 and analyze, chceck and test it. Small description how it works. 1. When the query is executed it checks if timeout > 0. 2. If yes it creates TimerTask and add it to the queue, then sends the query to server. 3. On timeout and if statement hasn't ended cancelStatement is called(). I've used Timer to don't create multiple threads with each statement. The AbstractJdbc2 have setQueryTimeout method, so DataSources and PolledConnections can utilze it to set Timer shared for all connections. The QueryExecutor has new method executeSynchronized (description in API). To prevent termination on next statement & run statements in current thread, the lock on QueryExecutor is needed (so no other thread will send other query until cancelStatement is fully called). This method can be more usefull then synchronized(...) block and can be used later. Some new utilities class has been added. The test code creates non tempolary tables to simulate long-run by creating data lock on two transactions. If the JDBC will go to Java 5, some of this code can use new java.util.concurent API. Kind regards, Radek Smogura