Groovy/SoapUI: 线程内循环不起作用

Groovy/SoapUI: Loop inside thread does not work

我正在做这样的事:

Iterator<String> iterator = requestList.iterator()

    (1..threadCount).each {

        Thread.start {

            while(iterator.hasNext()) {
                log.info iterator.next()
                Thread.sleep(50)
            }
        }
    }

鉴于 threadCount = 10requestList is ~115,我希望所有线程输出所有列表,每次都要求迭代器给它们下一个。

然而,我连10条日志都很难得到,通常是8条。

一切都在 SoapUI groovy 脚本步骤中完成,而不是 log.info 我实际上计划触发编号为 N 的 REST 请求。

我对这些线程做错了什么?

UPD

好吧,做了这么蠢的事来测试(并避免使用一个数组):

def array1 = all[0..5]
def array2 = all[6..11]


Thread.start{

    for(String r: array1) {
        log.info r
    }
}

Thread.start{

    for(String r: array2) {
        log.info r
    }
}

现在我完全没有输出或最多只有一个日志,尽管我预计有 12 个。 如何创建同时输出数据的线程?

更多

def threadCount=10

(0..threadCount).each { n ->

 Thread.start {

  (1..10).each {
       log.info "thread"+n+" says| "+it
  }
 }
}

输出为:

thread0 says| 1
thread3 says| 1
thread8 says| 1
thread2 says| 1
thread1 says| 1
thread9 says| 1
thread7 says| 1
thread5 says| 1
thread4 says| 1
thread0 says| 2

仅此而已。再一次,我或 groovy 怎么了? (希望groovy没事)

最后,问题是 SoapUI 在所有线程有机会获取下一个数字之前杀死主线程。

一个快速解决这个问题的方法是将 sleep 添加到 main 方法