数据库中显式锁和隐式锁有什么区别?
数据库中显式锁和隐式锁有什么区别?
What is the difference between an explicit and an implicit lock in database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
数据库中显式锁和隐式锁有什么区别?
What is the difference between an explicit and an implicit lock in database?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
隐式锁通常由 DBMS 自动放置。大多数 DBMS 允许开发人员或应用程序发出锁,称为显式锁。
Implicit locks are generally placed by the DBMS automatically. Most DBMS allow the developer or the application to issue locks which are referred to as explicit locks.
隐式锁定
Objectivity/DB 将在需要时为您的应用程序隐式获取适当的锁定。读取对象的操作将获得读锁;修改对象的操作将获得写锁。
显式锁定
隐式锁定获取应用程序需要的资源的访问权限。一般来说,Objectivity/DB 的自动锁定提供了足以满足大多数应用程序的联合数据库并发级别。
然而,某些应用程序可能需要提前保留对所有所需资源的访问权限。这样做的原因可能是为了在开始操作之前确保对必要对象的所需访问权限,或者防止其他会话修改对操作至关重要的对象。
需要提前保留对所有必需对象的访问的应用程序可以显式锁定对象。假设应用程序需要根据特定时间点的许多对象的状态来计算值。尽管应用程序无法同时检查所有必需的对象,但通过冻结对象的状态然后按顺序检查它们可以达到相同的效果。显式锁定有效地冻结了对象,因为只要它们被锁定,其他会话就无法修改它们。
Implicit Locking
Objectivity/DB will implicitly obtain the appropriate locks for your application at the point at which they are needed. An operation that reads an object will obtain a read lock; an operation that modifies an object will obtain a write lock.
Explicit Locking
Implicit locking obtains access rights to resources as they are needed by an application. In general, the automatic locking by Objectivity/DB provides a level of federated database concurrency that is sufficient for most applications.
Some applications, however, may need to reserve access to all required resources in advance. Reasons for doing so might be to secure required access rights to the necessary objects before beginning an operation, or to prevent other sessions from modifying objects critical to the operation.
An application needing to reserve access to all required objects in advance can explicitly lock objects. Suppose an application needs to calculate a value based upon the state of many objects at a specific point in time. Although the application cannot check all of the necessary objects simultaneously, it can achieve the same effect by freezing the state of the objects and then checking them in sequence. Explicit locking effectively freezes the objects, because no other session can modify them as long as they are locked.