In some cases, we need to share or pass variables between threads and thread groups in JMeter. There are a few ways to do this and using custom jars in JMeter is one of them. At JMeter documentation:
But sometimes we want to ensure synchronization between threads and thread groups. In this case, one of the best ways is to “write your own Java classes.”
Create the methods that you need in your test. In this example, we created methods about BlockingQueue operations.
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
public class Loadium {
private static LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
public static void put(Object obj) throws InterruptedException {
queue.put(obj);
}
public static Object take() throws Exception {
return queue.take();
}
public static Object get(long timeout) throws Exception {
return queue.poll(timeout, TimeUnit.MILLISECONDS);
}
public static void clear() throws Exception {
queue.clear();
}
public static int size() throws Exception {
return queue.size();
}
}
Copy and paste the jar file in <your JMeter path>/lib folder.
In this section, we will learn how to use the custom class in JMeter script.
Now we can call our custom method as follows in BeanShell Sampler element.
Run your test plan, and the result is below.
How To Use Custom Jars On Loadium?
For reporting purposes, go to Logs tab in your test report.
The result is below:
Please feel free to ask questions if you have any.
Happ load testing!