You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Ryabtsev Vladimir <v....@pflb.ru> on 2014/03/28 06:04:27 UTC
Equivalent of bsh.shared in groovy
Hi,
Is there any equivalent of bsh.shared namespace in JSR223/groovy?
Or the only way to save Java objects between calls is to use vars.putObject()?
Thanks,
V
RE: Equivalent of bsh.shared in groovy
Posted by Ryabtsev Vladimir <v....@pflb.ru>.
> HashMap isnt thread safe so you should prefer to use a ConcurrentHashMap
As I mentioned in first message, I needed analogue of bsh.shared. It's not thread safe too. In my case it doesn't matter because storage initialized just once (in setUp group) and used by other threads only for reading. It also may store other thread safe object, for example AtomicInteger. But you right, in general ConcurrentHashMap would be better solution.
> Which is a very bad reason to not put something in a package
First of all it's just principle and not ultimate solution. Anyone can put it into package as deep as he wants.
-----Original Message-----
From: Deepak Shetty [mailto:shettyd@gmail.com]
Sent: Monday, March 31, 2014 8:01 PM
To: JMeter Users List
Subject: Re: Equivalent of bsh.shared in groovy
your alternative is essentially the same thing - However a HashMap isnt thread safe so you should prefer to use a ConcurrentHashMap (and prefer putting interfaces in your signature as opposed to classes) -
>We didn't put SharedHashMap into any package, so it's just ready for
>use
without any import statements.
Which is a very bad reason to not put something in a package (And there are no good reasons)
On Mon, Mar 31, 2014 at 12:18 AM, Ryabtsev Vladimir <v....@pflb.ru>wrote:
> Thank you for your answer. I've thought out much simpler solution:
>
> import java.util.HashMap;
>
> public class SharedHashMap
> {
> public static HashMap GetInstance()
> {
> return instance;
> }
> static HashMap instance = new HashMap(); }
>
> This should be compiled, packaged into jar and put in lib directory.
> After that we can simply use in any groovy (or other language) script:
>
> HashMap sharedHashMap = SharedHashMap.GetInstance();
> sharedHashMap.put('myObject', myObject); //...
> MyObjectType myObject = (MyObjectType)sharedHashMap.get('myObject');
>
> We didn't put SharedHashMap into any package, so it's just ready for
> use without any import statements.
> This is full analogue of bsh.shared namespace with all of its
> advantages and disadvantages (like necessity of thread synchronization
> in case of modifying objects).
>
>
> -----Original Message-----
> From: Deepak Shetty [mailto:shettyd@gmail.com]
> Sent: Friday, March 28, 2014 7:53 PM
> To: JMeter Users List
> Subject: Re: Equivalent of bsh.shared in groovy
>
> you can always use a java object that holds onto its state statically
> ...Similar example here
>
> http://theworkaholic.blogspot.com/2013/03/sharing-session-ids-across-t
> hreads.html- doesnt use groovy but its the same concept
>
>
> On Thu, Mar 27, 2014 at 11:04 PM, Ryabtsev Vladimir
> <v.ryabtsev@pflb.ru
> >wrote:
>
> > Sorry, of course I meant I want to pass Java Objects between threads.
> > More exactly, I want to initialize some objects in setup Thread
> > Group and get access to them from all thread in main thread group.
> > Thus, I can use vars.putObject() because it stores variable only for
> > those thread which put it.
> > How can I share some objects between different threads if I'm using
> > JSR223/groovy?
> >
> > -----
> > V
> >
> >
> > -----Original Message-----
> > From: Ryabtsev Vladimir [mailto:v.ryabtsev@pflb.ru]
> > Sent: Friday, March 28, 2014 9:04 AM
> > To: user@jmeter.apache.org
> > Subject: Equivalent of bsh.shared in groovy
> >
> > Hi,
> >
> > Is there any equivalent of bsh.shared namespace in JSR223/groovy?
> > Or the only way to save Java objects between calls is to use
> > vars.putObject()?
> >
> > Thanks,
> > V
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > For additional commands, e-mail: user-help@jmeter.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org
Re: Equivalent of bsh.shared in groovy
Posted by Deepak Shetty <sh...@gmail.com>.
your alternative is essentially the same thing - However a HashMap isnt
thread safe so you should prefer to use a ConcurrentHashMap (and prefer
putting interfaces in your signature as opposed to classes) -
>We didn't put SharedHashMap into any package, so it's just ready for use
without any import statements.
Which is a very bad reason to not put something in a package (And there are
no good reasons)
On Mon, Mar 31, 2014 at 12:18 AM, Ryabtsev Vladimir <v....@pflb.ru>wrote:
> Thank you for your answer. I've thought out much simpler solution:
>
> import java.util.HashMap;
>
> public class SharedHashMap
> {
> public static HashMap GetInstance()
> {
> return instance;
> }
> static HashMap instance = new HashMap();
> }
>
> This should be compiled, packaged into jar and put in lib directory.
> After that we can simply use in any groovy (or other language) script:
>
> HashMap sharedHashMap = SharedHashMap.GetInstance();
> sharedHashMap.put('myObject', myObject);
> //...
> MyObjectType myObject = (MyObjectType)sharedHashMap.get('myObject');
>
> We didn't put SharedHashMap into any package, so it's just ready for use
> without any import statements.
> This is full analogue of bsh.shared namespace with all of its advantages
> and disadvantages (like necessity of thread synchronization in case of
> modifying objects).
>
>
> -----Original Message-----
> From: Deepak Shetty [mailto:shettyd@gmail.com]
> Sent: Friday, March 28, 2014 7:53 PM
> To: JMeter Users List
> Subject: Re: Equivalent of bsh.shared in groovy
>
> you can always use a java object that holds onto its state statically
> ...Similar example here
>
> http://theworkaholic.blogspot.com/2013/03/sharing-session-ids-across-threads.html-
> doesnt use groovy but its the same concept
>
>
> On Thu, Mar 27, 2014 at 11:04 PM, Ryabtsev Vladimir <v.ryabtsev@pflb.ru
> >wrote:
>
> > Sorry, of course I meant I want to pass Java Objects between threads.
> > More exactly, I want to initialize some objects in setup Thread Group
> > and get access to them from all thread in main thread group.
> > Thus, I can use vars.putObject() because it stores variable only for
> > those thread which put it.
> > How can I share some objects between different threads if I'm using
> > JSR223/groovy?
> >
> > -----
> > V
> >
> >
> > -----Original Message-----
> > From: Ryabtsev Vladimir [mailto:v.ryabtsev@pflb.ru]
> > Sent: Friday, March 28, 2014 9:04 AM
> > To: user@jmeter.apache.org
> > Subject: Equivalent of bsh.shared in groovy
> >
> > Hi,
> >
> > Is there any equivalent of bsh.shared namespace in JSR223/groovy?
> > Or the only way to save Java objects between calls is to use
> > vars.putObject()?
> >
> > Thanks,
> > V
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > For additional commands, e-mail: user-help@jmeter.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>
RE: Equivalent of bsh.shared in groovy
Posted by Ryabtsev Vladimir <v....@pflb.ru>.
Thank you for your answer. I've thought out much simpler solution:
import java.util.HashMap;
public class SharedHashMap
{
public static HashMap GetInstance()
{
return instance;
}
static HashMap instance = new HashMap();
}
This should be compiled, packaged into jar and put in lib directory.
After that we can simply use in any groovy (or other language) script:
HashMap sharedHashMap = SharedHashMap.GetInstance();
sharedHashMap.put('myObject', myObject);
//...
MyObjectType myObject = (MyObjectType)sharedHashMap.get('myObject');
We didn't put SharedHashMap into any package, so it's just ready for use without any import statements.
This is full analogue of bsh.shared namespace with all of its advantages and disadvantages (like necessity of thread synchronization in case of modifying objects).
-----Original Message-----
From: Deepak Shetty [mailto:shettyd@gmail.com]
Sent: Friday, March 28, 2014 7:53 PM
To: JMeter Users List
Subject: Re: Equivalent of bsh.shared in groovy
you can always use a java object that holds onto its state statically ...Similar example here
http://theworkaholic.blogspot.com/2013/03/sharing-session-ids-across-threads.html-
doesnt use groovy but its the same concept
On Thu, Mar 27, 2014 at 11:04 PM, Ryabtsev Vladimir <v....@pflb.ru>wrote:
> Sorry, of course I meant I want to pass Java Objects between threads.
> More exactly, I want to initialize some objects in setup Thread Group
> and get access to them from all thread in main thread group.
> Thus, I can use vars.putObject() because it stores variable only for
> those thread which put it.
> How can I share some objects between different threads if I'm using
> JSR223/groovy?
>
> -----
> V
>
>
> -----Original Message-----
> From: Ryabtsev Vladimir [mailto:v.ryabtsev@pflb.ru]
> Sent: Friday, March 28, 2014 9:04 AM
> To: user@jmeter.apache.org
> Subject: Equivalent of bsh.shared in groovy
>
> Hi,
>
> Is there any equivalent of bsh.shared namespace in JSR223/groovy?
> Or the only way to save Java objects between calls is to use
> vars.putObject()?
>
> Thanks,
> V
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org
Re: Equivalent of bsh.shared in groovy
Posted by Deepak Shetty <sh...@gmail.com>.
you can always use a java object that holds onto its state statically
...Similar example here
http://theworkaholic.blogspot.com/2013/03/sharing-session-ids-across-threads.html-
doesnt use groovy but its the same concept
On Thu, Mar 27, 2014 at 11:04 PM, Ryabtsev Vladimir <v....@pflb.ru>wrote:
> Sorry, of course I meant I want to pass Java Objects between threads.
> More exactly, I want to initialize some objects in setup Thread Group and
> get access to them from all thread in main thread group.
> Thus, I can use vars.putObject() because it stores variable only for those
> thread which put it.
> How can I share some objects between different threads if I'm using
> JSR223/groovy?
>
> -----
> V
>
>
> -----Original Message-----
> From: Ryabtsev Vladimir [mailto:v.ryabtsev@pflb.ru]
> Sent: Friday, March 28, 2014 9:04 AM
> To: user@jmeter.apache.org
> Subject: Equivalent of bsh.shared in groovy
>
> Hi,
>
> Is there any equivalent of bsh.shared namespace in JSR223/groovy?
> Or the only way to save Java objects between calls is to use
> vars.putObject()?
>
> Thanks,
> V
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>
RE: Equivalent of bsh.shared in groovy
Posted by Ryabtsev Vladimir <v....@pflb.ru>.
Sorry, of course I meant I want to pass Java Objects between threads.
More exactly, I want to initialize some objects in setup Thread Group and get access to them from all thread in main thread group.
Thus, I can use vars.putObject() because it stores variable only for those thread which put it.
How can I share some objects between different threads if I'm using JSR223/groovy?
-----
V
-----Original Message-----
From: Ryabtsev Vladimir [mailto:v.ryabtsev@pflb.ru]
Sent: Friday, March 28, 2014 9:04 AM
To: user@jmeter.apache.org
Subject: Equivalent of bsh.shared in groovy
Hi,
Is there any equivalent of bsh.shared namespace in JSR223/groovy?
Or the only way to save Java objects between calls is to use vars.putObject()?
Thanks,
V
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org