469,962 Members | 2,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,962 developers. It's quick & easy.

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 2218
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 £100 and TOMCAT is debiting
£10 while the other app is crediting £15

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 £105 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Marco Vezzoli | last post: by
1 post views Thread by Phil Campaigne | last post: by
175 posts views Thread by Sai Hertz And Control Systems | last post: by
15 posts views Thread by Dino Vliet | last post: by
4 posts views Thread by Wayne Fang | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.