pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Vladimir Stankovic <V.Stankovic@city.ac.uk>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: No exception with concurrent updates
Date: Wed, 14 Jul 2004 14:54:54 -0400
Message-ID: <1089831294.1549.31.camel@localhost.localdomain> (raw)
In-Reply-To: <E1Bkn6M-00020F-00@ms2.city.ac.uk>
References: <E1Bkn6M-00020F-00@ms2.city.ac.uk>

Vladimir,

Have you read how concurrency works in postgresql ?

Dave
On Wed, 2004-07-14 at 12:59, Vladimir Stankovic wrote:
> Dear all,
> 
> I wrote (extremely) simple programme in Java (jsdk1.4.2) to examine the 
> PostgreSQL's (v7.2.4, I know, rather obsolete) handling of concurrent 
> updates and I'm confused with the fact that the server (running on a remote 
> machine with Red Hat Linux 6.0) does not give me any kind of exception when 
> I execute the following code on the client machine running Win 2000. While 
> running the programme in the debug mode the excution just hangs when the 
> UPDATE query of the transaction2() is executed. Using setQueryTimeout() 
> won't help much since it is available as of 7.3 version, isn't it. I set 
> autocommit off and specify TRANSACTION_SERIALIZABLE on the Connection 
> objects. I'm using the pg73jdbc3.jar and NetBeans 3.5.
> 
> /*
>  * ConcurencyTest.java
>  * Created on 09 July 2004, 15:39
>  */
> import java.sql.*;
> 
> public class ConcurrencyTest 
> {    
>     Connection con1, con2; 
>     
>     public ConcurrencyTest()
>     {
>         /*
>           ConnectionManager object creates Connection and the
>           GetConnection() method returns the reference. Value of
>           128 specifies the JDBC connection (rather than ODBC).
>          */
>         con1 = new ConnectionManager(128).GetConnection();
>         con2 = new ConnectionManager(128).GetConnection();
>         
>         transaction1();
>         transaction2();      
>         
>         try 
>         {
>            con2.commit();
>            con1.commit();
>            //con1.close();
>            //con2.close();
>         }
>         catch (SQLException sqle)
>         {
>             System.out.println("Could not close the connection");
>         }
>         
>     }    
>     
>     public void transaction1()
>     {
>         try
>         {
>             con1.commit();
>             Statement sta1 = con1.createStatement();
>             sta1.setQueryTimeout(5);
> 
>             rs_1 = sta1.executeQuery("SELECT * FROM Orderline WHERE ol_o_id 
> = 1 AND ol_d_id = 1 AND ol_w_id = 1 AND ol_number = 4");
> 
>             while (rs_1.next())
>                 System.out.println(rs_1.getInt(8) + "\tT1");
>             rs_1.close();
>             
>             sta1.executeUpdate("UPDATE Orderline SET ol_quantity = 10 WHERE 
> ol_o_id = 1 AND ol_d_id = 1 AND ol_w_id = 1 AND ol_number = 4");
>             
>             sta1.close();
>         }
>         catch (SQLException sqle)
>         {
>             System.out.println("Error in Transaction 1: " + sqle);
>         }
>         
>     }
>     
>     public void transaction2()
>     {
>         try
>         {
>             con2.commit();
>             Statement sta2 = con2.createStatement();
>             sta2.setQueryTimeout(5);
> 
>             ResultSet rs_2 = sta2.executeQuery("SELECT * FROM Orderline 
> WHERE ol_o_id = 1 AND ol_d_id = 1 AND ol_w_id = 1 AND ol_number = 4");
>             while (rs_2.next())
>                 System.out.println(rs_2.getInt(8) + "\tT2");
>             rs_2.close();
>             
>             
>             sta2.executeUpdate("UPDATE Orderline SET ol_quantity = 20 WHERE 
> ol_o_id = 1 AND ol_d_id = 1 AND ol_w_id = 1 AND ol_number = 4");
> 
>             
>             sta2.close();
>         }
>         catch (SQLException sqle)
>         {
>             System.out.println("Error in Transaction 2: " + sqle);
>            
>         }
>         
>     }
>     
>     public static void main(String args[])
>     {
>         new ConcurrencyTest();
>     }
> }
> 
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 9: the planner will ignore your desire to choose an index scan if your
>       joining column's datatypes do not match
> 
> 
> 
> !DSPAM:40f57e51167398493720393!
> 
> 
-- 
Dave Cramer
519 939 0336
ICQ # 14675561




view thread (9+ messages)  latest in thread

Message-ID: <1089831294.1549.31.camel@localhost.localdomain>
Permalink:  ../1089831294.1549.31.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1089831294.1549.31.camel@localhost.localdomain

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: pg@fastcrypt.com, V.Stankovic@city.ac.uk
  Subject: Re: No exception with concurrent updates
  In-Reply-To: <1089831294.1549.31.camel@localhost.localdomain>
  References: <E1Bkn6M-00020F-00@ms2.city.ac.uk> <1089831294.1549.31.camel@localhost.localdomain>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox