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 <[email protected]>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:[email protected]] > 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 <[email protected] > >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:[email protected]] > > Sent: Friday, March 28, 2014 9:04 AM > > To: [email protected] > > 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: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
