|
Answer» There are 3 types of locks. - Shared lock: – This lock can ensure that two or more mainframe programs can read from the locked resource at a time but MODIFYING is not allowed.
- This lock is also called a read lock as it is used only for reading data items.
- Since these are read locks, they support read integrity and ensures that when a record is being read, that won't be updated.
- Shared locks can also be used to prevent any kind of updates of record.
- Consider a scenario where we have A=100 initially and we have 2 transactions that want to read A. If one among them wants to update or modify A, then there are chances where the other transaction would read the wrong value. Here, if we use a shared lock, the data UPDATION would be prevented until the transaction has completed reading.
- Update lock: – This lock allows the program to use the shared or locked resource to CHANGE it.
- This lock requires TABLESPACE OR LOCKSIZE TABLE along with cursor-based SELECT having FOR UPDATE OF clause.
- A table with this lock allows data read but does not allow modification of the locked data. Whenever the application tries to update the data, the U lock will be promoted to Exclusive Lock.
- Exclusive lock: – This lock RESTRICTS all user types to access locked space.
- Consider an example where A=100 initially, and we have a transaction that wants to deduct some value say 25 from A. This can be allowed by placing an exclusive lock on A so that whenever any other transaction wants to read or write from it, the lock prevents it.
|