Forum Discussion
M_McDonald
16 years agoSuper Contributor
I wanted to try to do this "on the cheap", so I tried this code in a Groovy step:
This code adds the current thread to a load test context property and sleeps until the 5th thread, which attempts to interrupt the sleep for all other running threads. However, the interrupt seems to be ignored.
There are probably lots of synchronization issues with this approach, but I don't see why this simple case does not work.
def testRunnerContext = context.getProperty("LoadTestRunner").context
def threadPool = testRunnerContext.getProperty("threadPool")
log.info "Thread " + Thread.currentThread().id + " starting, threadPool size = " + threadPool.size
if (threadPool.size() >= 4) {
threadPool.each { thread ->
thread.interrupt()
}
} else {
threadPool.add(Thread.currentThread())
try {
sleep(10000);
}
catch (InterruptedException ie) {
log.info "Thread " + Thread.currentThread().id + " interrupted."
}
}
log.info "Thread " + Thread.currentThread().id + " finished."This code adds the current thread to a load test context property and sleeps until the 5th thread, which attempts to interrupt the sleep for all other running threads. However, the interrupt seems to be ignored.
There are probably lots of synchronization issues with this approach, but I don't see why this simple case does not work.