当多个线程 运行 并行时,如何在 jmeter 中保留线程变量?
How to keep Thread variables in jmeter when multiple Threads are running in parallel?
我有 多个并行线程 运行 。
任何请求都可以从任何线程多次触发。
我使用 vars.put() 将我的请求变量存储在 beanshell 中。
我已经使用 vars.get() 在另一个 beanshell 中检索了这个变量。
但是当 Thread 并行运行时,我希望在检索变量时
应该检索当前线程的值。
有点像在 java 中我们如何使用 this 关键字并获取当前对象的 属性。
我该怎么做?
int ThreadNum = ctx.getThreadNum();
String[] Request_values= new String[Request_variables.length];
how will I conacat the thread number to the Request_values?
JMeter 变量基本上是 ThreadLocal 因此您不需要做任何事情。
如果您需要在线程 2 中访问线程 1 的变量值,您可以使用 ${__threadNum} function 作为前缀或后缀将当前线程号附加到 JMeter 变量名称。
you can put your string array using vars.putObject("","");
at thhis time you can concat your thread number at keyname.
int ThreadNum = ctx.getThreadNum();
String[] Request_values= new String[Request_variables.length];
vars.putObject("Key_"+ThreadNum ,Request_values);
我有 多个并行线程 运行 。 任何请求都可以从任何线程多次触发。 我使用 vars.put() 将我的请求变量存储在 beanshell 中。 我已经使用 vars.get() 在另一个 beanshell 中检索了这个变量。 但是当 Thread 并行运行时,我希望在检索变量时 应该检索当前线程的值。 有点像在 java 中我们如何使用 this 关键字并获取当前对象的 属性。 我该怎么做?
int ThreadNum = ctx.getThreadNum();
String[] Request_values= new String[Request_variables.length];
how will I conacat the thread number to the Request_values?
JMeter 变量基本上是 ThreadLocal 因此您不需要做任何事情。
如果您需要在线程 2 中访问线程 1 的变量值,您可以使用 ${__threadNum} function 作为前缀或后缀将当前线程号附加到 JMeter 变量名称。
you can put your string array using vars.putObject("",""); at thhis time you can concat your thread number at keyname.
int ThreadNum = ctx.getThreadNum();
String[] Request_values= new String[Request_variables.length];
vars.putObject("Key_"+ThreadNum ,Request_values);