【文档摘要】J2EE Persistence - Controlling Concurrent Access to Entity Data with Locking

本文探讨了J2EE持久层中控制实体数据并发访问的两种锁定方式:乐观锁和悲观锁。乐观锁通过版本字段实现,而悲观锁则通过开启事务获取长期锁。不同锁模式如OPTIMISTIC、OPTIMISTIC_FORCE_INCREMENT、READ、WRITE、PESSIMISTIC_READ、PESSIMISTIC_WRITE和PESSIMISTIC_FORCE_INCREMENT分别适用于不同场景。选择合适的模式需要根据应用需求来平衡读写冲突和性能。
摘要由CSDN通过智能技术生成

short term read lock / long term write lock


Optimistic Locking: version column

Pessimistic Locking: create a transaction to obtain long term lock


Lock Modes:

OPTIMISTIC: Obtain an optimistic read lock for all entities with version attributes.

OPTIMISTIC_FORCE_INCREMENT: Obtain an optimistic read lock for all entities with version attributes, andincrement the version attribute value.

READ:  OPTIMISTIC.

WRITE: OPTIMISTIC_FORCE_INCREMENT.

PESSIMISTIC_READ: immediately obtain a long-term read lock on the data toprevent the data being modified or deleted. Other transactions may read the data while the lock is maintained, but not modify or delete the data.

PESSIMISTIC_WRITE: immediately obtain a long-term write lock on the data toprevent the data being read, modified ordeleted.

PESSIMISTIC_FORCE_INCREMENT: immediately obtain a long-term lock on the data toprevent the data being modified or deleted, and increment the version attribute value.

NONE: no additional locking.


Question:

How to choose which mode to use????


参考资料

https://docs.oracle.com/javaee/7/tutorial/doc/persistence-locking001.htm#GKJHZ

https://blogs.oracle.com/carolmcdonald/entry/jpa_2_0_concurrency_and

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值