473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

simultaneous use of JDBC and libpq

Hi,

I am wondering if it is thread-safe to use both JDBC and libpq
simultaneously.

On a Linux, JDBC is used by Tomcat and libpq is used by a client
software written in C language. So JDBC and libpq are used by two
different programs.
If the same row in the same table is updated (update SQL command)
through libpq and
read (select SQL command) by JDBC, then would it cause a thread problem?
I am not using any transaction, and using just select, update, and
sometimes insert.

I am using PostgreSQL 7.3.6 with pg73jdbc3.jar downloaded and libpq that
came with Redhat Enterprise 3.

Thank you very much in advance.

Bob


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #1
2 2361
alltest1 wrote:
Hi,

I am wondering if it is thread-safe to use both JDBC and libpq
simultaneously.

On a Linux, JDBC is used by Tomcat and libpq is used by a client
software written in C language. So JDBC and libpq are used by two
different programs.
If the same row in the same table is updated (update SQL command)
through libpq and
read (select SQL command) by JDBC, then would it cause a thread problem?
I am not using any transaction, and using just select, update, and
sometimes insert.


There are no threads involved here - Tomcat/client-app will be different
processes, and both have their own connection to the database.

You might need to consider concurrency issues within the database
though, e.g. assume your bank account has $B!r(B100 and TOMCAT is debiting
$B!r(B10 while the other app is crediting $B!r(B15

TOMCAT: SELECT amount FROM bank_accounts WHERE acct_id = 1;
OTHER: SELECT amount FROM bank_accounts WHERE acct_id = 1;
TOMCAT: UPDATE bank_accounts SET amount=90 WHERE acct_id = 1;
OTHER: UPDATE bank_accounts SET amount=115 WHERE acct_id = 1;

Oops - not $B!r(B105 at all. To solve this, you need to lock the table or the
row(s) in question, e.g.
SELECT FOR UPDATE ... WHERE acct_id = 1;]#

See the section on "concurrency control" in the manuals for full details.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #2
Yes, it is safe. The JDBC and the libpq app will share nothing between
each other, so there can not be any threading issues between them.
You can only have thread safety issues inside the same application which
uses multiple threads sharing resources between each other.

Cheers,
Csaba.

On Wed, 2004-06-23 at 16:24, alltest1 wrote:
Hi,

I am wondering if it is thread-safe to use both JDBC and libpq
simultaneously.

On a Linux, JDBC is used by Tomcat and libpq is used by a client
software written in C language. So JDBC and libpq are used by two
different programs.
If the same row in the same table is updated (update SQL command)
through libpq and
read (select SQL command) by JDBC, then would it cause a thread problem?
I am not using any transaction, and using just select, update, and
sometimes insert.

I am using PostgreSQL 7.3.6 with pg73jdbc3.jar downloaded and libpq that
came with Redhat Enterprise 3.

Thank you very much in advance.

Bob


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marco Vezzoli | last post by:
Hi all, I'm using solaris 8 gcc 3.0.1 postgres 7.3.4 psycopg 1.1.2 apache 1.3.19 python 2.1.1 mod_python 2.7.8 compiled with DSO
1
by: Phil Campaigne | last post by:
Hi All, Took a break from developing on pgsql 7.3 to set up network printing where I added another host(localhost 193.168.1.2) in red hat network settings. Later, I could start postmaster but...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
1
by: Semaj | last post by:
Environment: DB2 8.1.4; Windows 2000 We are evaluating the feasibility of upgrading our production DB from 7.2 to 8.1. During this process we've encountered an error when starting our...
2
by: Jim Crate | last post by:
I'm trying to build a client program to access a database using the libpq interface on MacOS X 10.3.3 using CodeWarrior 9. PostgreSQL is at version 7.4.2. It compiles ok, but I get a link...
2
by: Adam Smith | last post by:
Installation of 7.4.2, even with just ./configure : gmake step ==> _________________________________________________ gmake: Leaving directory...
15
by: Dino Vliet | last post by:
Hi folks, probably this is a question you've heard so many times but I wasn't able to find a solution to it. I'm using a shell script to create a textfile for me. It looks like...
4
by: Wayne Fang | last post by:
Hi, For various reasons (parallel structure with existing code, commonality of concepts, etc), we have C language functions implemented that use libpq to make a new connection to the same Postgres...
1
by: loosecannon_1 | last post by:
Hello everyone, I am hoping someone can help me with this problem. I will say up front that I am not a SQL Server DBA, I am a developer. I have an application that sends about 25 simultaneous...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.