In Jmeter, how to set a variable number of threads using the beanshell selector variable?

In JMeter, I have a group of threads, and I want to control how many threads are executed using the jmeter variable. In the thread group, I set the number of threads equal to ${numThreads} . I have a group of installation threads that has a bean shell sampler with the following (this is always done before the main group of test threads):

 vars.put("numThreads","5"); 

If I installed numThreads in a user-defined variable configuration item in the installation thread group, it will use the correct number of threads. However, I want to control it using the variable I defined in the bean shell sampler, and it does not work. I see that the variable is being created, and I can print the value in the log, but when I use the bean shell sampler, the group of threads incorrectly creates 5 threads (creates 0 threads). The only thing I can think of is that they create variables, but maybe the user configuration element creates it as an integer type? When I debug a variable type, it displays as a string, regardless of whether it is set in the user configuration parms or bean shell sampler.

 log.debug(vars.get("numThreads").getClass().getName()); // this prints java.lang.String for both 

Why is the thread group not creating the correct number of threads based on the bean shell variable?

+2
java jmeter
source share
1 answer

Ok, I figured it out. It seems that the variables are thread specific and the properties are global for the whole test. Thus, setting the variable in the installation thread group was out of scope when my main thread group started. Now Im sets the property in the beanshell setupgroup and uses the following in the main thread group:

configuring beanshell threadgroup: props.put ("ThreadCount", "3");

In the main thread group, I can use the following to start the correct number of threads: $ {__ P (ThreadCount)}

It’s still not clear why the user variable configuration item worked - it should generate properties, not variables or something like that.

+4
source share

All Articles