We decided this in my company in two situations, independently, using some variations in the record record "record lock". In one system, a lock record is created when the record enters the “queue” as a new item; another lock record is created when the user retrieves the record from the queue.
In any case, you cut it when a user copy of your software opens a queue entry for work, the lock record should be in the database with some unique identification information about your user written on it. It must be unique to lock the record, and possibly the lock level (which means that two locks of the same level cannot exist in the same record) and identifies the user who opened the record as “owning” it for the purpose of making changes. This record is a lock should be kept as long as the user has a record open in his software.
The ability to “break” locks can be achieved by simply reassigning the lock to another user in combination with the usual polling of the lock object using the source software to lock the user; if at any time the user is no longer the owner, the lock was “broken”, and the user has the option to re-lock the lock (violation of another new user lock) or simply switch.
Now, if the user software crashes, they will still have a write lock. It may also happen that the operation to remove the lock failed (this can happen in situations where real data is in another database and you cannot provide a universal transaction). In this case, you will need a mechanism to remove the "lost" locks or force the user to delete them. If the elements to be blocked are time sensitive, you will need to create several redundant levels of removal of the locks (perhaps setting a time that once a minute breaks any lock older than X minutes or, as you know, is orphaned because this user is no longer logged in )
source share