473,399 Members | 4,192 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,399 software developers and data experts.

DB2 commit synchronization

Nothing got wrong with DB2 COMMIT, db2 cfg, ...
Even you did an "insert some_id+1 ..." immediately after you did "select
max(some_id) from .... " in session1. This will not block the operations
which submitted by the other processes/threads. Before the INSERT, DB2
will not prevent the other SELECT MAX(some_id) from this table.
So the following case could happen,
Suppose in session A:
Begin a transactionA
Select max(id) from mytable;
.... at this moment Session B also Begin transaction B, and submit the
SELECT MAX ?BR>Session A will do the INSERT id+1 ...
.... if Session B wants to do INSERT too, it has to wait ...

The simple solution:
Lock the table before you do SELECT MAX ... release the lock after
INSERT ...
This will cause potential lock contention, and hurt concurrency.
I will suggest you use SEQUENCE to replace the column SOME_ID. Please
check with the db2 manual.
You can also use Identity Column, but I will suggest Sequence ...
BTW, AFAIK, db2 introduce SEQUENCE since V7.2 or V7.1 + fixpak3.

Regards,
FRX

===================
From: sergiu (sg******@qct.ro)
Subject: DB2 commit synchronization
Newsgroups: comp.databases.ibm-db2
Date: 2003-09-29 01:33:37 PST
Hello,
I am developing a java application (client-server), that is supposed
to support lots of users (over 100). I am encoutering a problem with
DB2 commit statement.
There is an portion of code on the server side, that needs to be
thread safe. Therefore I've made that method synchronized. Inside that
method, i have to do an "select max(some_id) from .... " and
imediately after i do an "insert some_id+1 ...". I close the
connection (it is obtained through JNDI datasource), and exit the
method.
However, if multiple clients try to access that method at the same
time, they are put on hold until one of them terminates (witch is the
behaviour i expect). But, if a very short time passes between 2 runs
in that method (less than 20ms), the second client, when does the
"select max(some_id) ..." it gets the old id, not the one updated by
the previous client. I have tried in many ways to get the damn thing
working (setted autocommit false, and just before closing doing an
manual commit), but it seems that the JDBC driver (at least) is
returning from the commit method, and not actually doing the commit
(if i wait 30ms everything is fine, but this is not what i want). I'm
sure i can find a workaround for exactly this situation (static
variables,etc.) but what will I do if i encounter a situation in
witch this workaround doesn't apply?
Is there any way to force DB2 to make a commit when i tell it so, and
not to return from the statement until everything is written on the
disk?
I'm using DB2 v7.1 on an RedHat 7.3 machine with an ext3
filesystem(dual proc ... etc.).
Thanks,
Sergiu.

Nov 12 '05 #1
0 5378

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

Similar topics

11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
2
by: janet | last post by:
HI, I had a question on auto-commit in DB2 EEE V8 on AIX V5. Here is my example.. there are two script A.sh , B.SQL A.sh is following:
4
by: scott | last post by:
hi all, Thx to any one that can offer me help, it will be much appreciated. iv got a multithreaded program and need to use thread synchronization. The synchronization does not have to...
0
by: Rod | last post by:
I orginally posted this to microsoft.public.sqlserver.ce but had not received any responses. I have a CF.NET application (C#) with a SqlCE database. We had originally planned to use SQL...
12
by: emma_middlebrook | last post by:
Hi Say you had N threads doing some jobs (not from a shared queue or anything like that, they each know how to do their own set of jobs in a self-contained way). How can you coordinate them so...
0
by: lbrtchx | last post by:
Say you need to serve the same Web content from a number of IP address, which you need to keep out there with high availability requirements ~ I think Web Services would be a good candidate for...
0
by: sundman.anders | last post by:
Hi all! I have a question about thread synchronization and c++ streams (iostreams, stringstreams, etc). When optimizing a program for a multicore processor I found that stringstream was causing...
3
by: CKKwan | last post by:
Dear All, Can synchronize a class, any function is called and the entire class is locked. Can synchronize a method What if I need to Lock a class only when specific method is call?
15
by: ingejg | last post by:
I am starting to study internet synchronization, and my head is still spinning since internet is not my forte, however my boss is breathing down my neck at the moment. Our company has only one...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.