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?
Ok I figured it out. Looks like variables are thread specific and properties are global to the entire test. So setting a variable in the setup threadgroup was out of scope when my main thread group starts. Now Im setting a property in the setupgroup beanshell and using the following in the main threadgroup:
setup threadgroup beanshell: props.put("threadCount","3");
In the main threadgroup I can use the following to start the correct number of threads: ${__P(threadCount)}
Still no idea why the user defined variables config element was working - it must generate properties rather than variables or something.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments