Java – How to pass a variable from one Thread Group to another in JMeter


I have a JMeter test with 2 Thread Groups – the first is a single thread (which creates some inventory) and the second has multiple threads (which purchase all the inventory). I use BeanShell Assertions and XPath Extractors to parse the returned value (which is XML) and store variables (such as the ids of the items to be purchased).

But, values that are created in the first Thread Group, whether extracted into standard ${jmeter} type variables, or ${__BeanShell(vars.get("jmeter"))} type vars, are not available in the second Thread Group. Is there anyway to create a variable in the first Thread Group and make it visible to the second?

Best Solution

I was not able to do this with variables (since those are local to individual threads). However, I was able to solve this problem with properties!

Again, my first ThreadGroup does all of the set up, and I need some information from that work to be available to each of the threads in the second ThreadGroup. I have a BeanShell Assertion in the first ThreadGroup with the following:

${__setProperty(storeid, ${storeid})};

The ${storeid} was extracted with an XPath Extractor. The BeanShell Assertion does other stuff, like checking that storeid was returned from the previous call, etc.

Anyway, in the second ThreadGroup, I can use the value of the "storeid" property in Samplers with the following:


Works like a charm!