I'm doing smth like:
Iterator<String> iterator = requestList.iterator()
(1..threadCount).each {
Thread.start {
while(iterator.hasNext()) {
log.info iterator.next()
Thread.sleep(50)
}
}
}
Given that threadCount = 10
and requestList is ~115
, I expect all threads to output all the list, each time asking iterator to give them next.
However, I hardly even get 10 logs, usually 8.
Everything is done inside SoapUI groovy script step, instead of log.info I actually plan triggering a REST request with number N.
What am I doing wrong with these threads?
UPD
Okay, did smth stupid like this, to test (and avoid using one array):
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
}
}
And now I have no output at all or one log at most, though I expect 12. How do I create threads that will output data simultaneously?
EVEN MORE
def threadCount=10
(0..threadCount).each { n ->
Thread.start {
(1..10).each {
log.info "thread"+n+" says| "+it
}
}
}
Output is:
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
And nothing more. Again, what's wrong with me or groovy? (hope groovy is fine)