MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

z/OS DB2 Stored Procedure Returning Duplicate Results

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Thu Oct 20, 2005 11:21 am    Post subject: z/OS DB2 Stored Procedure Returning Duplicate Results Reply with quote

We have a stored procedure that allocates a control number based on current date and time (down to hundredths of a second). To verify that the number is not duplicated, it inserts this number into a DB2 table which has a unique index on this number. If a duplicate is detected (SQLCode = -803), the procedure will add 1 to the number and try again. It will continue this until it gets a +0 SQLCode (or it gets some other code or it times out).

We have a WebSphere application that invokes this routine to get a control number. When it is configured for multi-thread processing, it appears to be getting more than one response with the same control number.

Does anyone know what might be causing this?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Thu Oct 20, 2005 11:27 am    Post subject: Reply with quote

Quote:

If a duplicate is detected (SQLCode = -803), the procedure will add 1 to the number and try again. It will continue this until it gets a +0 SQLCode (or it gets some other code or it times out).


Bithead,

what does the websphere application do when the other process is in the loop of inserting the seqnum in -803 condition?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Thu Oct 20, 2005 11:36 am    Post subject: Reply with quote

It should wait. I have to determine if the problem is in the WebSphere application or the Stored Procedure. I have no access to the Java code at this time and so I must start by investigating the procedure. The problem occurs when multiple threads hit at the same time. Either the stored procedure is still in memory and other threads are picking up the results or the threads are picking up a dirty buffer somewhere.

I may add displays to the procedure to display the code added.
Back to top
View user's profile Send private message
a_seshu
Beginner


Joined: 30 Sep 2004
Posts: 16
Topics: 4
Location: Chennai

PostPosted: Fri Oct 21, 2005 3:56 pm    Post subject: Reply with quote

Hi Bithead,

I feel waiting in a loop for 0 sql code when processing in multi threaded evironment with high volumes of concurrency is not a good approach of programming. Having said that, I have a suggestion for you. you can lock the table in your program before you want to update or insert into the table and then when you are done, you can unlock it. So that any parellel process which is trying to lock the table should have to wait until the previous lock is released.

EXEC SQL LOCK TABLE <TABLENAME> IN EXCLUSIVE MODE END-EXEC would work to lock it so that only one process at a time can have an exclusive control on the table and when you are done, you can issue a commit in your program. But then i think in your bind pamaeters you should have RELEASE(COMMIT).


Thanks,
Seshu.
_________________
I dont think I would ever stop learning. - Seshu.
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group