I've implemented my own Sampler by extending AbstractJavaSamplerClient of Jmeter. In the setup test I want to read a bunch of files from a dir and populate the request List and then share it with all Threads/Sampler Instances during runTest phase. Currently I use a Lock in order to allow a single thread to access and populate it at the start, and then the rest don't bother to redo the task. The code looks like this:
@Override
public void setupTest(JavaSamplerContext context) {
...
MyLock.lock();
try {
// setup requests
if (MyFileList == null) {
// read the files and populate MyFileList
}
finally {
MyLock.unlock();
}
}
Each time a Sampler thread hits this lock, it's gonna test if MyFileList is populated, if not it's gonna populate otherwise it's gonna release the lock. I used a ReentrantLock for this. But I was wondering if I could totally avoid the lock and have a single thread initialization phase at the beginning and then let other threads to proceed.
