gpt4 book ai didi

concurrency - GPars 锁返回 null

转载 作者:行者123 更新时间:2023-12-04 03:14:36 25 4
gpt4 key购买 nike

当我尝试锁定表中的一行时,有时会返回 null。那是什么意思?我验证域实例在锁定之前不为空:

println state
state = State.lock(state.id)
println state

这个输出:

State 1
null

(“状态1”是状态的字符串表示)

最佳答案

通过这样做,您将从 GORM 乐观锁定(在更新之前比较对象的版本)切换为悲观锁,这意味着读取操作将被阻塞,直到锁被释放。如果您想检索一个值,请使用下面的闭包(请参阅方法 returnValue):

State.withPessimisticLock(state.id) { Object lockedDomain ->
return "OK"
}.onNotFound { ->
return "NG"
}
assert result.returnValue == "OK"

顺便说一句,交易是必需的,所以你的问题中返回的null可能意味着你的对象不在交易中。

关于concurrency - GPars 锁返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14024436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com