In JMeter I have a thread group and I want to control how many threads are run using a jmeter variable. In the thread group I'm setting Number of Threads equal to ${numThreads}
. I have a setup thread group that has a bean shell sampler with the following (this always runs before the main test thread group):
vars.put("numThreads","5");
If I set numThreads
in a user defined variables config element in the setup thread group it will use the correct number of threads. However I want to control it using a variable I defined in a bean shell sampler and it is not working. I can see the variable is being created and I can print the value in the log but when I use the bean shell sampler the thread group does not correctly create 5 threads (it creates 0 threads). The only thing I can think of is they both create variables but maybe the user defined config element creates it as an integer type? When I debug the type of the variable it shows as a string regardless of if it is set in a user defined parms config or bean shell sampler.
log.debug(vars.get("numThreads").getClass().getName()); // this prints java.lang.String for both
Why does the thread group not create the correct number of threads based on the bean shell variable?