jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <>
Subject Re: A place for global init function?
Date Sat, 04 Jun 2005 14:03:00 GMT
On 6/3/05, Seth Ladd <> wrote:
> > No problem - glad that the BSH Sampler is proving useful.
> >
> > I added in case we needed it, but all we've ended up using is the
> > BeanShell server ...
> > [We use that to make changes to a property that is then used to
> > control throughput.]
> It's very useful.  For instance, I am using it to test remote spring
> services using spring's httpinvoker.  Using the bean shell is much
> easier than writing a custom java class.
> I'd love to figure out how to get one object instance available to all
> threads.  That would be nice, but right now one object instance per
> thread is fine.

I've just re-checked, and the BSH Sampler creates new version of the
interpreter for each Sampler in each thread.

So any variables in the script are local to the sampler (but will
persist across loops).

However, one can use vars.get("VAR") and vars.put("VAR",value); to
get/set thread variables.

JMeter does not currently have any global variables, as far as I can see.

But I've just found that there is a shared namespace within BeanShell
- see "Special Variables and Values", which is on page 34 of the BSH
Manual version 1.3.

This can be used as follows within the bshrc script:

  if (bsh.shared.myobj == void) {
     print("myobj = void");
     bsh.shared.myobj=123; // Or something a bit more useful
  } else {
     print("myobj = " + bsh.shared.myobj);

[I'm not entirely sure whether synchronized() works or is a no-op, so
you might need to adjust the ramp-up time]

Note that the bsh.shared namespace is not reset at the end of a test
run, so this may not be suitable for repeated test runs.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message