The "groovy based mechanism" is JMeter Properties <https://jmeter.apache.org/usermanual/properties_reference.html>, there is *props* shorthand which allows setting/reading properties like:

myObj = new AnyObject()

props.put('myObj', myObj)

//then somewhere else:

myObj = props.get('myObj')

See Top 8 JMeter Java Classes You Should Be Using with Groovy <https://www.blazemeter.com/blog/top-8-jmeter-java-classes-you-should-be-using-with-groovy> for more information on this and other JMeter API shorthands available for Groovy

Also there is Inter-Thread Communication Plugin <https://jmeter-plugins.org/wiki/InterThreadCommunication/> so if you need to pass Strings <https://docs.oracle.com/javase/7/docs/api/java/lang/String.html>you can just use it and won't have to write a single line of code.

On 6/14/2022 4:50 PM, Tong Sun wrote:
Hi,

In the JMeter Best Practices:
https://jmeter.apache.org/usermanual/best-practices.html

It says

To "Share variables between threads and thread groups",

there are various options:

    - Store the variable as a property - properties are global to the JMeter
    instance
    - Write variables to a file and re-read them.
    - Use the bsh.shared namespace - see above
    <https://jmeter.apache.org/usermanual/best-practices.html#bsh_variables>
    - Write your own Java classes


Using the bsh.shared namespace seems to be an appealing option, However,
the BeanShell scripting is *deprecated*, so here is my question:

Would the following still be the recommended best practices?

The sample .bshrc files contain sample definitions of getprop() and
setprop() methods.

Another possible method of sharing variables is to use the "bsh.shared"
shared namespace. For example:

if (bsh.shared.myObj == void){

     // not yet defined, so create it:

     myObj = new AnyObject();

}

bsh.shared.myObj.process();

Rather than creating the object in the test element, it can be created in
the startup file defined by the JMeter property "beanshell.init.file". This
is only processed once.


If not, is there any groovy based mechanism that provides the same
functionalities?

Thanks

Reply via email to