How to implement a "pessimistic lock" in an asp.net application?

I would like to get advice from anyone who has come up with something like “pessimistic blocking” in an asp.net application. This is the behavior I'm looking for:

  • User A opens order # 313
  • User B is trying to open order No. 313, but he is informed that user A had an order opened exclusively in X minutes.

Since I have not previously implemented this functionality, I have a few design questions:

  • What data should I attach to an order record? I think:
    • LockOwnedBy
    • LockAcquiredTime
    • LockRefreshedTime

I would consider a record unlocked if LockRefreshedTime <(Now - 10 minutes).

  • How can I guarantee that locks do not hold longer than necessary, but also do not expire unexpectedly?

I really like jQuery, so approaches that use a client script are welcome. This will be an internal web application, so I can be pretty liberal with bandwidth / loops. I am also wondering if “pessimistic blocking” is an appropriate term for this concept.

+5
source share
2 answers

It looks like you are most there. I don’t think you really need LockRefreshedTime, but it really doesn’t add anything. You can also use LockAcquiredTime to decide when the lock is out of date.

, , , . , , , .

, (.. ), , , , A B, B A.

, . , - , , , .

" " .

+8

.

  • .
  • , .
  • .
  • . , .

:

User_ID, //who locked
Lock_start_Time,
Locked_Row_ID(Entity_ID), //this is primary key of the table of locked row.
Table_Name(Entity_Name) //table name of the locked row.

- , .

, 4 . - , .

+1

All Articles