I discovered a nice solution to this problem. I put the BeanShell code into an init file (see the manual) and called it using the __BeanShell function. As the manual says, "A single instance of a function may be called from multiple threads." The first call to the function reads the file and sets up the data structure, and subsequent calls (from any thread) read the data from memory. And the __BeanShell function takes care of concurrency for me: "the function execute() method is synchronised."
As another simplification, I used straight Java instead of FileServer to read the file. FileServer shares its file pointers between threads, which is not what I wanted. Cheerio, Bennett. -- Bennett McElwee -----Original Message----- From: sebb [mailto:[EMAIL PROTECTED] Sent: Thursday, 26 October 2006 11:36 am To: JMeter Users List Subject: Re: BeanShell global synchronisation & variables On 25/10/06, Bennett McElwee <[EMAIL PROTECTED]> wrote: > I have a BeanShell sampler that has an initialisation method that reads > a file into a data structure. Since a separate BeanShell interpreter is > created for each thread, this work is being repeated for every thread. > Two problems here: > > - Wasted work -- the file only needs to be read once, and then the data > structure can be shared across threads. > > - Synchronization -- If two threads try to read the file at the same > time, they might step on each other (since I use JMeter's FileServer). > I plan to do two things: > > - Synchronise the routine that reads the file into the data structure so > it only happens once. > > - Put the data structure into a JMeter variable so all threads can share > it. > > And I have a couple of questions: > > 1. What should I synchronize on? I really want to synchronise on the > FileEntry object created by the FileServer, but I can't get hold of it. > I could synchronise on the FileServer itself but that's overkill. The > problem is that there's no way in BeanShell to create an appropriately > global, cross-thread object to synchronise on. > You might be able to use one of the variables exposed to the BeanShell script to walk back up the hierarchy to find something suitable. > 2. Are JMeter variables shared across threads? No. Otherwise it would not be possible to have different values of (say) the username for different threads. Properties are global, but I can't see how to use those for synchronisation. > I would appreciate your thoughts. > You might find it worthwhile creating your own version of the File Server. S. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This communication, including any attachments, is confidential. If you are not the intended recipient, you should not read it - please contact me immediately, destroy it, and do not copy or use any part of this communication or disclose anything about it. Thank you. Please note that this communication does not designate an information system for the purposes of the Electronic Transactions Act 2002. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

