Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgjQ6-000348-9D for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 21:55:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TgjQ4-0000oW-Py for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 21:55:49 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgjC7-0006fo-Co for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 21:41:23 +0000 Received: from news.hub.org ([200.46.204.72]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgjC2-00018h-RZ for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 21:41:22 +0000 Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.5/8.14.5) with ESMTP id qB6LfHR9065901 for ; Thu, 6 Dec 2012 17:41:17 -0400 (AST) (envelope-from news@news.hub.org) Received: from news.hub.org (news@localhost) by news.hub.org (8.14.5/8.14.5/Submit) with NNTP id qB6LHai9063836 for pgsql-jdbc@postgresql.org; Thu, 6 Dec 2012 17:17:36 -0400 (AST) (envelope-from news) Received: by 10.66.87.232 with SMTP id bb8mr657511pab.1.1354828655146; Thu, 06 Dec 2012 13:17:35 -0800 (PST) Received: by 10.50.7.198 with SMTP id l6mr2532208iga.3.1354828654798; Thu, 06 Dec 2012 13:17:34 -0800 (PST) X-Newsgroups: pgsql.interfaces.jdbc Date: Thu, 6 Dec 2012 13:17:34 -0800 (PST) In-Reply-To: <016e01cdd3f5$1dbdaaf0$593900d0$@yahoo.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.42.209.109; posting-account=Y2aaMAoAAABH9DJbJzVnp21hz7eFNnF7 References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> <50C0E09A.4070408@ttc-cmc.net> <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> <5a57e55f-1b8f-4f37-a271-af9fb1a9ffab@googlegroups.com> <016e01cdd3f5$1dbdaaf0$593900d0$@yahoo.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <51765e16-c35e-412d-b2f4-f8ab1a67f2f3@googlegroups.com> Subject: Re: Statement.setQueryTimeout() with autoCommit=false From: =?UTF-8?Q?Pavel_Arno=C5=A1t?= Injection-Date: Thu, 06 Dec 2012 21:17:35 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable To: pgsql-jdbc@postgresql.org X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org I added e.printStackTrace() to catch block, just to be sure, and no excepti= on is thrown. I described result poorly, code with TimerTask does not *time= outs*, it *ends* after 5 seconds without error, just like my first example = without explicit transaction and autoCommit set to true. According to javadoc, st.cancel() after st.execute() should be ok. Does someone use synchronous replication? Without query timeouts, it's not = very usable IMO. On Thursday, December 6, 2012 10:03:17 PM UTC+1, "David Johnston" wrote: > It may be that I am wrong and at the moment haven't tested your examples = but >=20 > it seems odd that you can st.cancel() after st.execute() without getting >=20 > some kind of exception (which you are ignoring in your catch block). >=20 > Without some more detail I either need to do some testing on my own or le= ave >=20 > it to more qualified individuals to help. I'll admit I am making untested >=20 > assumptions here about how the interaction should behave (but often my id= ea >=20 > of "should behave" differs from reality). >=20 >=20 >=20 > David J. >=20 >=20 >=20 >=20 >=20 > > -----Original Message----- >=20 > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- >=20 > > owner@postgresql.org] On Behalf Of Pavel Arno=C4=8F=C5=BC=CB=9Dt >=20 > > Sent: Thursday, December 06, 2012 3:33 PM >=20 > > To: pgsql-jdbc@postgresql.org >=20 > > Subject: Re: [JDBC] Statement.setQueryTimeout() with autoCommit=3Dfalse >=20 > >=20 >=20 > > If that's how it works, why this code timeouts after 5 seconds?: >=20 > >=20 >=20 > > -- >=20 > > Connection conn =3D DriverManager.getConnection(url, props); >=20 > > conn.setAutoCommit(false); >=20 > > final PreparedStatement st =3D conn.prepareStatement("INSERT IN= TO >=20 > test >=20 > > VALUES('xxx')"); >=20 > > st.setQueryTimeout(5); >=20 > > st.execute(); >=20 > >=20 >=20 > > Timer timer =3D new Timer(true); >=20 > >=20 >=20 > > TimerTask cancelTimer =3D new TimerTask() { >=20 > > public void run() { >=20 > > try { >=20 > > st.cancel(); >=20 > > } catch (SQLException e) { } >=20 > > } >=20 > > }; >=20 > >=20 >=20 > > timer.schedule(cancelTimer, 5000); >=20 > >=20 >=20 > > conn.commit(); >=20 > > -- >=20 > >=20 >=20 > > Quick look at AbstractJdbc2Statement.execute() shows me that >=20 > > setQueryTimeout() works with Timer/TimerTask like this one. >=20 > >=20 >=20 > > Thanks, >=20 > > Pavel >=20 > >=20 >=20 > > On Thursday, December 6, 2012 7:36:53 PM UTC+1, "David Johnston" wrote: >=20 > > > > -----Original Message----- >=20 > > > >=20 > > > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- >=20 > > > >=20 > > > > owner@postgresql.org] On Behalf Of dmp >=20 > > > >=20 > > > > Sent: Thursday, December 06, 2012 1:15 PM >=20 > > > >=20 > > > > To: pgsql-jdbc@postgresql.org >=20 > > > >=20 > > > > Cc: pavel.arnost@loutka.cz >=20 > > > >=20 > > > > Subject: Re: [JDBC] Statement.setQueryTimeout() with >=20 > > > > autoCommit=3Dfalse >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > Exactly. >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > According to the Java API: >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > void setAutoCommit(boolean autoCommit) throws SQLException >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > Sets this connection's auto-commit mode to the given state. If >=20 > > > > a >=20 > > > >=20 > > > > connection is in auto-commit mode, then all its SQL statements will >=20 > > > > be >=20 > > > >=20 > > > > executed and committed as individual transactions. Otherwise, its >=20 > > > > SQL >=20 > > > >=20 > > > > statements are grouped into transactions that are terminated by a >=20 > > > > call to >=20 > > > >=20 > > > > either the method commit or the method rollback. By default, new >=20 > > > >=20 > > > > connections are in auto-commit mode. >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > By setting setAutoCommit(false) you are deciding to tell the >=20 > > > > database your >=20 > > > >=20 > > > > code will determine when to commit the transaction. Thereby I would >=20 > > > > say >=20 > > > >=20 > > > > overiding setQueryTimeout(). >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > danap. >=20 > > > >=20 > > > >=20 > > > >=20 > > > Even within an manually administered transaction the setting of >=20 > > > >=20 > > > "setQueryTimeout()" will (should?) act on the individual statements >=20 > > > that >=20 > > > >=20 > > > make up the transaction. If any individual statement within the >=20 > > > transaction >=20 > > > >=20 > > > exceeds the limit that statement will fail and thus put the >=20 > > > transaction into >=20 > > > >=20 > > > a "failed" state where a rollback (possibly to savepoint) is required. >=20 > > > The >=20 > > > >=20 > > > transaction itself does not constitute a statement and as such it can >=20 > > > run >=20 > > > >=20 > > > indefinitely long regardless of the presence of a statement timeout. >=20 > > > >=20 > > > >=20 > > > >=20 > > > David J. >=20 > > > >=20 > > > >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > Dave Cramer wrote: >=20 > > > >=20 > > > > > Why would the query timeout at all ? >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > The query timeout is for long running queries. If the query takes >=20 > > > >=20 > > > > > longer than n seconds it will timeout. >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > Dave >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > Dave Cramer >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > dave.cramer(at)credativ(dot)ca >=20 > > > >=20 > > > > > http://www.credativ.ca >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > On Thu, Dec 6, 2012 at 12:04 PM, =20 > > > >=20 > > > > > > wrote: >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > Hi, >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > does setQueryTimeout work with autoCommit=3Dfalse? When >=20 > > > > > autoCommit >=20 > > > >=20 > > > > is >=20 > > > >=20 > > > > > true, this code timeouts after 5 seconds (as expected): >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > ~ >=20 > > > >=20 > > > > > ~ >=20 > > > >=20 > > > > > ~ >=20 > > > >=20 > > > > > -- >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > But if I set autoCommit to false, this code timeouts after 30 >=20 > > > >=20 > > > > > seconds on read timeout: >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > -- >=20 > > > >=20 > > > > > ~ >=20 > > > >=20 > > > > > ~ >=20 > > > >=20 > > > > > ~ >=20 > > > >=20 > > > > > -- >=20 > > > >=20 > > > > > >=20 > > > >=20 > > > > > I'm confused what's setQueryTimeout() method for, why it >=20 > > > > > doesn't >=20 > > > >=20 > > > > > work with manual transactions? >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > >=20 > > > >=20 > > > > -- >=20 > > > >=20 > > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make >=20 > > > >=20 > > > changes >=20 > > > >=20 > > > > to your subscription: >=20 > > > >=20 > > > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 > > > >=20 > > > >=20 > > > >=20 > > > >=20 > > > >=20 > > > >=20 > > > >=20 > > > -- >=20 > > > >=20 > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >=20 > > > >=20 > > > To make changes to your subscription: >=20 > > > >=20 > > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 > >=20 >=20 > >=20 >=20 > >=20 >=20 > > -- >=20 > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make >=20 > changes >=20 > > to your subscription: >=20 > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 >=20 >=20 >=20 >=20 >=20 >=20 > --=20 >=20 > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >=20 > To make changes to your subscription: >=20 > http://www.postgresql.org/mailpref/pgsql-jdbc --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc