Re: simultaneous use of JDBC and libpq

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: simultaneous use of JDBC and libpq
Дата
Msg-id 40D9A0CF.508@archonet.com
обсуждение исходный текст
Ответ на simultaneous use of JDBC and libpq  (alltest1 <alltest1@covad.net>)
Ответы Re: simultaneous use of JDBC and libpq  (Marco Colombo <marco@esi.it>)
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: psql
Следующее
От: Tom Lane
Дата:
Сообщение: Re: FW: problems with installing postgres