Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
Originally posted by Dmitri Christo:
...just want to add this: Even if I dont explicitly check if the record is locked, shouldn't my book method at least block if the record I try to book is under some other user's lock? The book method consists of lock-update-unlock methods and since those are remote, the lock part of the book method should block right?
I base this on the fact that with non-gui multiple clients my locking works fine.
Also, it's generally not advisable to lock a record at the point where a user starts to enter information and unlock it when they're done and the record is saved. Instead, let the user enter the new information and then let them confirm persisting the data. Only at that point should you lock, update and unlock the record.
Originally posted by Dmitri Christo:
So what is the point to have the user do all these actions, like go for a seemingly available record and start entering new information if you dont have it locked already? What if the client thinks while entering the new data, that a book will be successful while in reality some other thread might have jumped in and finished working on that record already.
So, in my tests, I started 2 terminals and brought up two guis, selected same record and clicked the book button. For both users the dialog came up prompting them to enter new owner id for the same record! That was programmatically correct, since the code hadn't reached the lock method for that record yet.. Now I believe that is not a suitable behavior..
Isn't the user 'tricked' in some way if they start doing a bunch of work on the record only to find they can't complete since that record is locked by someone else?
Pessimistc: Pessimistic locking is an approach where an entity is locked in the database for the entire time that it is in application memory (often in the form of an object)
Pessimistic: .[..]Had a collision been detected, e.g. the data had been updated by another process after it had originally been read into memory, then the collision would need to be resolved.
Optimistic locking -- that's where you assume things will go well and design your locks so that they handle conflicts as the exceptional case
Pessimistic locking -- the converse where you assume conflicts are likely and create some kind of reservation system where sections are locked while they are edited
Originally posted by Dmitri Christo:
...the interesting thing here is that there are conversations like this
where they suggest the opposite...
Isn't the user 'tricked' in some way if they start doing a bunch of work on the record only to find they can't complete since that record is locked by someone else?
[ March 16, 2008: Message edited by: Dmitri Christo ]
SCJP 5.0 (93%), SCWCD (98%), SCJD (377/400), SCBCD (100%)
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |