Add support for saving variables between different threads
ydarlico opened this issue · 3 comments
Hello! Add support for saving and using variables between different thread groups in the same class.
In my case, in setupThreadGroup() I receive a number of variables via JDBC requests. And then I want to set parameters in the next thread group (threads(count_vu)/ rampup/ loop) using the values from the last thread.
But the script crashes with an error because it does not see the variables. I save them through
jdbcSampler(//some request//).vars("count_vu"),
jsr223Sampler("JSR223 Sampler",
c -> {
int count_vu = Integer.parseInt(c.vars.get("count_vu_1"));
c.props.setProperty("count_vu_uc42", c.vars.get("count_vu_1"));
...
If there is another way to store and handle them, please indicate how.
JMeter variables are scoped to threads.
Usually, for simple scenarios, I just use JMeter or System properties as you did in the example.
There might be other more complex means of sharing like storing in a file, using a queue, db, etc. One of which might be through the usage of Inter Thread Communication plugin.
@ydarlico do you think we should close this issue? Does my answer help? Or do you think we should do something else in this regard?
@rabelenda Yes, you can close the task.
For those who stumble upon it, I want to say that I solved my problem of simultaneous initialization of threads by converting jdbcSampler + jsr223Sampler into a separate class with code purely in java. This class is located before testPlan and, when executed, saves all parameters for future threads in map.