Return-Path: X-Original-To: apmail-jmeter-user-archive@www.apache.org Delivered-To: apmail-jmeter-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C35BA100B8 for ; Tue, 1 Apr 2014 06:44:04 +0000 (UTC) Received: (qmail 89673 invoked by uid 500); 1 Apr 2014 06:44:04 -0000 Delivered-To: apmail-jmeter-user-archive@jmeter.apache.org Received: (qmail 89270 invoked by uid 500); 1 Apr 2014 06:44:01 -0000 Mailing-List: contact user-help@jmeter.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "JMeter Users List" Delivered-To: mailing list user@jmeter.apache.org Received: (qmail 88830 invoked by uid 99); 1 Apr 2014 06:43:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Apr 2014 06:43:58 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of v.ryabtsev@pflb.ru designates 213.199.154.80 as permitted sender) Received: from [213.199.154.80] (HELO emea01-db3-obe.outbound.protection.outlook.com) (213.199.154.80) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Apr 2014 06:43:52 +0000 Received: from AMSPR07MB033.eurprd07.prod.outlook.com (10.242.81.17) by AMSPR07MB034.eurprd07.prod.outlook.com (10.242.81.20) with Microsoft SMTP Server (TLS) id 15.0.908.10; Tue, 1 Apr 2014 06:43:29 +0000 Received: from AMSPR07MB033.eurprd07.prod.outlook.com ([169.254.8.62]) by AMSPR07MB033.eurprd07.prod.outlook.com ([169.254.8.55]) with mapi id 15.00.0908.008; Tue, 1 Apr 2014 06:43:29 +0000 From: Ryabtsev Vladimir To: JMeter Users List Subject: RE: Equivalent of bsh.shared in groovy Thread-Topic: Equivalent of bsh.shared in groovy Thread-Index: Ac9KQSBMP0zur6ANQ1a9rUIWOvxJQgACUN3wABTVl4AAhIQsoAASq8+AAB4bd8A= Date: Tue, 1 Apr 2014 06:43:28 +0000 Message-ID: References: <9fc53440732343cf857f6053501cebe4@DB3PR07MB042.eurprd07.prod.outlook.com> <92ddeabb6ec14d39b0e863345e5cdf8c@DB3PR07MB042.eurprd07.prod.outlook.com> In-Reply-To: Accept-Language: ru-RU, en-US Content-Language: ru-RU X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [195.42.96.251] x-forefront-prvs: 016885DD9B x-forefront-antispam-report: SFV:NSPM;SFS:(10019001)(6009001)(428001)(51704005)(377454003)(13464003)(199002)(189002)(252514010)(164054003)(83322001)(76796001)(19580405001)(69226001)(95666003)(77096001)(95416001)(93136001)(4396001)(65816001)(76786001)(94316002)(79102001)(92566001)(87936001)(98676001)(46102001)(81472001)(49866001)(50986001)(80022001)(76576001)(86362001)(56776001)(19580395003)(74316001)(90146001)(51856001)(63696002)(54356001)(81342001)(94946001)(15975445006)(54316002)(76482001)(53806001)(20776003)(33646001)(74482001)(83072002)(97336001)(2656002)(80976001)(47976001)(15202345003)(85852003)(59766001)(74706001)(47446002)(85306002)(66066001)(4477795002)(77982001)(93516002)(81542001)(56816005)(87266001)(31966008)(81686001)(74876001)(81816001)(47736001)(74662001)(97186001)(99396001)(74502001)(74366001)(24736002);DIR:OUT;SFP:1102;SCL:1;SRVR:AMSPR07MB034;H:AMSPR07MB033.eurprd07.prod.outlook.com;FPR:D6CFF114.12C19D09.F3D5129F.86E8E1EB.20406;MLV:sfv;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (: pflb.ru does not designate permitted sender hosts) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: pflb.ru X-Virus-Checked: Checked by ClamAV on apache.org > 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 j= ust once (in setUp group) and used by other threads only for reading. It al= so may store other thread safe object, for example AtomicInteger. But you r= ight, 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]=20 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 thr= ead safe so you should prefer to use a ConcurrentHashMap (and prefer puttin= g interfaces in your signature as opposed to classes) - >We didn't put SharedHashMap into any package, so it's just ready for=20 >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 wro= te: > 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 =3D 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 =3D SharedHashMap.GetInstance();=20 > sharedHashMap.put('myObject', myObject); //... > MyObjectType myObject =3D (MyObjectType)sharedHashMap.get('myObject'); > > We didn't put SharedHashMap into any package, so it's just ready for=20 > use without any import statements. > This is full analogue of bsh.shared namespace with all of its=20 > advantages and disadvantages (like necessity of thread synchronization=20 > 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=20 > ...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=20 > >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=20 > > 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=20 > > those thread which put it. > > How can I share some objects between different threads if I'm using=20 > > 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=20 > > 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