In Jmeter how do I set a variable number of threads using a beanshell sampler variable?

George

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?

George

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.

edited at
0

Comments

0 comments
Login to comment

Related

How do i remove empty parameter using beanshell preprocessor in jmeter

How to transfer a variable in java sampler to jmeter?

How to set ChromeProfile using Jmeter WebDriver Sampler?

Beanshell type of variable assertion on Jmeter

Jmeter Debug Sampler | How to save all variable values to CSV

How to update User Defined Variable in JMeter in JSR223 Sampler?

JMeter - Exception when using Beanshell as JSR223 Sampler with file

Store Jmeter sampler properties value using beanshell preprocessor

Writing Variables using Beanshell Sampler in JMeter into a txt/csv file

How do I write a function with variable number of arguments using pointers?

How do I store the number of rows affected in a variable using php?

How do I call a row number by using a variable in VBA?

How do i find/count number of variable in string using Python

Jmeter, BeanShell Sampler and Summary Report

How do I set an environment variable for Ansible itself not using shell?

How do I set a variable inside a recipe using a case statement?

How do I set the class of a variable using pipes?

How do I set a variable in an Impala query using HUE?

How do I set an array size using an atomic variable in Chapel?

How do I set a local variable using a CASE statement

How do I set the background color of a styled div using a variable?

How do I override the response content in a JMeter WebDriver sampler test?

JMeter setting user defined variable in beanshell not working

Error on accessing Output Variable in beanshell preprocessor in Jmeter

Jmeter: Run HTTP sampler n times using the variable value from SetUp thread group variable

How do I echo a sum of a variable and a number?

How do I test if a variable is a number in Bash?

How do I create a variable number of variables?

How do I create a global variable that is thread-specific in C using POSIX threads?