Stopping a user thread conditionally in JMeter

ctx.getThread().stop() sets the "stop" flag in the current thread, it works anywhere the JMeterContext ctx is exposed.

I have just done and verified it in a complex test script.


There are at least 2 options on how you can conditionally stop test thread or even the whole test:

  1. Use Test Action sampler in combination with If Controller
  2. Use Beanshell Sampler or PostProcessor and invoke setStopThread method of SampleResult class. See How to use BeanShell guide for example. For reference:

    if (condition){
        SampleResult.setStopThread(true); // for Beanshell Sampler
        prev.setStopThread(true); // for Beanshell Post Processor
    }
    

Tags:

Jmeter