Apache JMeter is an open source tool that can be used to measure the performance of Java applications. The JMeter can be used to test a wide range of Java applications like web, EJB, web services etc. I am not going to elaborate more on this, and you can get more information about this from the Apache JMeter website at http://jakarta.apache.org/jmeter/

The JMeter can also be extended, to create your own test plans. In this section I will explain the steps needed to create a custom JavaRequest sampler, and run it using JMeter.

To write the code you need to add the ApacheJMeter jar files to your classpath. The below code describes the simple JavaSampler:

package com.test;

import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;

 * @author ggeorge
public class MyTestJavaSampler implements JavaSamplerClient {

    public void setupTest(JavaSamplerContext arg0) {

    public SampleResult runTest(JavaSamplerContext arg0) {
        SampleResult sr = new SampleResult();
        sr.setResponseMessage("This is my first message");
        return sr;

    public void teardownTest(JavaSamplerContext arg0) {

    public Arguments getDefaultParameters() {
        Arguments args = new Arguments();
        args.addArgument("Name", "");
        args.addArgument("Password", "");
        return args;

  • Create a jar file for this code, and place in under the <jmeter_install_dir>/lib/ext directory.
  • Start JMeter and when you try to create a new JavaRequest sampler, you should be able to select the new class that you created.

You can customize this class for whatever performance test you want to run.