jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryabtsev Vladimir <v.ryabt...@pflb.ru>
Subject RE: Equivalent of bsh.shared in groovy
Date Tue, 01 Apr 2014 06:43:28 GMT
> 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.ryabtsev@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


Mime
View raw message