Use JMeter to test your EJB

Source: Internet
Author: User
Tags log log jboss application server

Some performance benchmarks for EJBS are necessary and helpful, with a lot of testing methods and tools, but I recently discovered that Apache JMeter is an excellent tool for benchmarking. Unfortunately, JMeter does not provide a universal sampler (sampler) that can test arbitrary ejbs, but we can create one ourselves.

First, let's take a quick look at Apache JMeter, a 100% pure Java desktop application that can be used for stress testing and performance measurement. It was originally designed for Web application testing but later extended to other test areas.

In this article, I use the JBoss application server to run my EJB. The implementation of other containers should also be very similar.

1. First create a factory (Factory) class for EJB

The first thing we need to do is create a simple singleton factory class to create an EJB client instance for your test. The reference code is as follows:

  public class MyServiceFactory {
  private static final Log log = LogFactory.getLog(MyServiceFactory.class);
   private static MyService service;
  private static MyServiceFactory me;
  private MyServiceFactory() { }
   static {
  MyServiceFactory.me = new MyServiceFactory();
   }
  public static MyServiceFactory getInstance() {
   return MyServiceFactory.me;
  }
  public MyService getService() {
  if (MyService.service == null) {
  try {
  log.info("Loading the service...");
  Context ctx = new InitialContext();
  service = (MyService)ctx.lookup ("MyAction/remote");
  if (service == null) {
  log.error ("Didn't get the service!");
  }
  } catch (NamingException e) {
  log.error("Error looking up the remote service", e);
   return null;
  }
  }
  return service;
  }
   }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.