什么是假锁?
-悲观锁定是一种方法,其中锁定实体直到该实体的事务完成.锁可以限制或阻止其他用户表单与数据库中的该实体一起使用.
锁范围
-锁定范围可能是
>整个数据库(数据库锁定),
>桌子(桌子锁),
>行的集合(页面锁)或
>单行(行锁).
悲观主义中的不同锁定模式
从docs开始.
LockMode.WRITE is acquired automatically when Hibernate updates or inserts a row.
LockMode.UPGRADE can be acquired upon explicit user request using SELECT ... FOR UPDATE on databases which support that syntax.
LockMode.UPGRADE_NOWAIT can be acquired upon explicit user request using a SELECT ... FOR UPDATE NOWAIT under Oracle.
LockMode.READ is acquired automatically when Hibernate reads data under Repeatable Read or Serializable isolation level. It can be re-acquired by explicit user request.
LockMode.NONE represents the absence of a lock. All objects switch to this lock mode at the end of a Transaction. Objects associated with the session via a call to update() or saveOrUpdate() also start out in this lock mode.
现在,根据您的情况,如果第一个执行,则将是2号值.然后将不允许其他更新.请记住,在请求后会自动获取LockMode.WRITE,这表明锁的当前持有者(方法2中的myClass)打算在您锁定行的情况下更新该实体.然后,它将禁止任何人(method1中的myClass)读取,更新和删除实体.
希望这很清楚.