The requirement is to stop the JMeter test after desired sample count is achieved. I have tried following approach...but the threads are not stopping as expected.

Please let me know how to solve the problem.

Setup thread group:
Beans shell sampler:
Declared a property total sample count with value 0
Subsequent thread groups:


  • get the value of property total sample count
  • Increase total sample count by 1
  • Put back the value in total sample count.
  • If the total sample count is equal to desired sample count
  • Stop the thread
  • Stop the test.

I am facing this issue:
1. The threads continue to run even the sample count reaches to desired sample count.

One more update is I am testing APIs and the hits are very high...ex within two minutes around 5k is achieved.

Suggest me if there is any problem with the approach or is there any better way to solve the problem.

  • Does this help? jmeter-archive.org/… so instead you would force the shutdown once the count is reached by stopping the thread. What OS are you running?
    – mutt
    Mar 18, 2017 at 3:34
  • I am working on Mac OS...I am using stop test in post processor
    – Raj
    Mar 18, 2017 at 5:14
  • I'm not familiar with mac, can you locate the process ID and then directly kill it?
    – mutt
    Mar 18, 2017 at 5:15
  • Thanks for your response. My requirement is to stop the test automatically as the script will be running from Jenkins integration
    – Raj
    Mar 18, 2017 at 7:03

1 Answer 1


I would suggest the following setup:

  1. Add an If Controller to your Test Plan and use ${__counter(,)} > 100 as the condition. Replace 100 with your desired samples count. __counter() is a JMeter Function which returns the value incremented by 1 each time it's being called.
  2. Put Test Action sampler as a child of the If Controller and apply the following configuration:

    • Target: All Threads
    • Action: Stop

    You can also use Stop Now as a target, the difference is that Stop "asks" threads to stop gracefully and Stop Now forcefully terminates them therefore you may see extra errors connected with this

In regards to your current approach troubleshooting take a look at jmeter.log file for any Beanshell-related errors. If everything goes well you should see something like Stop Test detected by thread: Thread Group X-X. If not - you should see something like Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: XXX

  • I can see Stop Test detected by thread: Thread Group X-X and no other errors are observed. But the sample count doesn't stop at reaching desired point.
    – Raj
    Apr 10, 2017 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.