Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Threading Message
Hi,
 
I would like to know the best approach.
 
I have 10 different screens accessing the same table for an unique order number. Once a screen requests a unique number the same is generated and stored in this table and this value is sent back to the screen. This becomes a problem when the requests are concurrent. We had used table level locks for this purpose. Is there a better approach like request/message/thread queuing so that only one access happens at any point of time and other requests are queued up and serviced async?
 
Thanks
BV
Posted 3-Jul-12 23:20pm
Comments
E.F. Nijboer at 4-Jul-12 4:29am
   
Table level locks? Are you using a database? In that case, use an auto incremented field.
Member 8648508 at 4-Jul-12 4:34am
   
Thanks mate. Auto Increment is not suitable here as this is a Unique Order Number that is being generated. Something like this.
Format:
YYYYMMDD+MAX(COUNT(*) FROM TABLE)
 
This number for today will be 2012070401, 2012070402, 2012070403....
 
for tomorrow will be 2012070501, 2012070502 and so on
E.F. Nijboer at 4-Jul-12 5:02am
   
You could of course add another table that has a date and the last identity of that previous day. This way you can get the desired Order number by finding the matching record in the new table within the range. You then take the date and add the identity after you subtract the last identity of the previous date from the record you find. It isn't the most beautiful solution though, but its an idea.
It might actually work if you use this in a two step way to create an id because this way you make sure the id constructed is always unique.
Member 8648508 at 4-Jul-12 8:26am
   
Thanks mate. Would this solve 10 or more concurrent requests for unique order number? I would like to keep the current table structure intact if possible and do the queuing only at the C# code level.
E.F. Nijboer at 4-Jul-12 9:34am
   
Well, it must because the identity column is the primary key and therefor unique, otherwise it would violate this contraint.
Member 8648508 at 9-Jul-12 1:32am
   
Hi dude, the Identity number must start with 1 daily.
 
This order number for today will be 2012070901, 2012070902, 2012070903.... for tomorrow will be 2012071001, 2012071002 and so on.
 
I recon we need to look for a more generic requests queuing system. First in First out implementation.
E.F. Nijboer at 9-Jul-12 3:35am
   
You would need to store the last ID of the day and subtract it from it from each ID the next day. That way it will start with 1 each day.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 295
1 OriginalGriff 273
2 Aajmot Sk 234
3 Marcin Kozub 205
4 Richard MacCutchan 200
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100