View previous topic :: View next topic |
Author |
Message |
eshwar Beginner
Joined: 05 May 2008 Posts: 3 Topics: 1
|
Posted: Mon May 05, 2008 10:24 pm Post subject: locking of the table in cics program while reading table. |
|
|
i need to handle locking of the table exclusively in cics program while reading table.
i know two ways to do this .
1.
we can use RR isolation instead of CS isolation level but this is not prfarable as it raises performence issue since it locks all pages .
2.
we can use lock table statement in program but this also not preferable as it raises performence issue since it locks entire table space
can any body suggest me to do in better way so that there will not be any performence issue.
Regards,
Eshwar. |
|
Back to top |
|
 |
Terry_Heinze Supermod
Joined: 31 May 2004 Posts: 391 Topics: 4 Location: Richfield, MN, USA
|
Posted: Tue May 06, 2008 9:18 am Post subject: |
|
|
I don't understand. You want to "lock the table exclusively", but don't want your locking to have performance issues. That seems contradictory. What do you want to lock? The table? The page? The row you're reading? If you are doing "read only", do a SELECT with the FOR READ ONLY clause and use CS and do not specify WITH UR. _________________ ....Terry |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue May 06, 2008 9:47 am Post subject: |
|
|
as terry said, why are you worried about locking a table?
first, why is this true: Quote: | i need to handle locking of the table exclusively in cics program while reading table |
the last thing you want to do is lock a table in a cics region. If you would give us an idea of what you are trying to accomplish, we could give some hints.
keep in mind the db2 reorgs can reorg a table without a table lock. I have rarely seen a situation whereby you need to lock a table. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
eshwar Beginner
Joined: 05 May 2008 Posts: 3 Topics: 1
|
Posted: Thu May 08, 2008 1:15 am Post subject: |
|
|
i have a situation where ID gets created by adding 1 to the max of (ID) of table. when two users creating ID at the same time will get the same ID .since two parallel cics sessions read the same table to get the max of (id) from the table . obviously this should not happen thats why i would like to have lock for the row which has been read so that the other user who is creating at the same will not be able to access the same row of the table. hope u got my requirement now. can u pls suggest is there any way to have row level locking of table in program itself. |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Thu May 08, 2008 7:45 am Post subject: |
|
|
you can specify row level locking during the table create.
again, program initiated locking (explicitly executing 'lock' sql) is not the way to go.
you should also look into identity columns.
or a loop:
do until sqlcode = 0
select maxid
update maxid where maxid = prev-maxid
endloop
though this code is a primative solution, you have a situation where the fault lies in the design. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
eshwar Beginner
Joined: 05 May 2008 Posts: 3 Topics: 1
|
Posted: Tue May 20, 2008 1:25 pm Post subject: |
|
|
this situation can be handled using ENQ ., it wil lock the resource which is given in ENQ command .this we need to code just before getting max id of the table .once the insert is successful on a table we can release the reource using DEQ. |
|
Back to top |
|
 |
RMi Beginner
Joined: 21 Jun 2006 Posts: 8 Topics: 0 Location: India
|
Posted: Mon Jun 02, 2008 5:53 am Post subject: |
|
|
Eshwar,
I have a question here on the ENQ. Does ENQ work across CICS regions? You stated that your concern is to avoid two different CICS regions getting the same value through the MAX function. |
|
Back to top |
|
 |
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Jun 03, 2008 2:54 am Post subject: |
|
|
you could use a cursor for update, which would 'lock' your row until the update current cursor and commit (or end of task).
the cursor would effectively enq your row, thus saving you the additional code of deq.
since the cursor lock on the row is db2, it would therefore be effective in any environemnt (batch contention, cross region, etc...)
but you have not responded this week, assume you have your solution. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
 |
videlord Beginner
Joined: 09 Dec 2004 Posts: 147 Topics: 19
|
Posted: Wed Jun 04, 2008 9:44 pm Post subject: |
|
|
eshwar wrote: | i have a situation where ID gets created by adding 1 to the max of (ID) of table. when two users creating ID at the same time will get the same ID .since two parallel cics sessions read the same table to get the max of (id) from the table . obviously this should not happen thats why i would like to have lock for the row which has been read so that the other user who is creating at the same will not be able to access the same row of the table. hope u got my requirement now. can u pls suggest is there any way to have row level locking of table in program itself. |
2 options, easy to solve your issue:
1. define this ID as Generated ... as identity...
2. in DB2 V8, create SQEUENCE object |
|
Back to top |
|
 |
|
|