2

我正在尝试集成测试 Gorm 悲观锁,并通过多线程同时模拟来自多个服务器的访问,但在每个线程中我都没有得到预期的结果。这是我的代码:

@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

我不知道发生了什么,我认为我的 Hibernate sessionFactory 没有绑定到每个线程,并且我应该工作的 Domain.withTransaction ,但它没有。

有什么帮助吗?

4

1 回答 1

2

它与集成测试的设置方法有关,我在内存中引导数据。一旦我将它移到 Bootstrap,线程的闭包就可以绑定休眠会话!无论如何谢谢!!

于 2012-09-14T12:48:13.357 回答