我正在嘗試集成測試Gorm悲觀鎖,並且使用多線程同時模擬多個服務器的訪問,但是在每個線程中我都沒有得到預期的結果。這是我的代碼:GORM GPARS集成測試
@Test
void testLockInBetweenCheck() {
def tid = IdocTidInfo.findByTid("AC10870D0E12504F3E88D575") //here tid is not null
withPool{
[1,2].eachParallel{ tids ->
IdocTidInfo.withTransaction{ tid ->
def t = IdocTidInfo.findByTid("AC10870D0E12504F3E88D575") // here is t is null
我無法弄清楚發生了什麼,我認爲我的SessionFactory未綁定到每個線程,而且Domain.withTransaction我應該工作,但事實並非如此。
任何幫助?
發佈問題的答案並將其標記爲接受的解決方案 – j4y