Im using the following code to stop a thread using jsr223 sampler on a specific condition.
Thread group.stop(Thread.currentThread.getname())
But the jmeter engine is ignoring the above condition and proceeding.
Can some one pls help on the right function.
Regards
Shankar
2
Answers
Call on the SampleResult
See:
https://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler
https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html#setStopThread-boolean-
The correct function would be
ThreadGroup.stopThread(java.lang.String threadName, boolean now)
Also be aware that JMeterThread is not the same as JVM Thread, i.e. they have different “names”.
So you need to amend your code to look something like:
where
ctx
is a shorthand for JMeterContextYou can also check out The Groovy Templates Cheat Sheet for JMeter to learn what else could be done using Groovy scripting.