Jmeter5.0入门介绍

  1. 从 http://jmeter.apache.org/download_jmeter.cgi 地址下载最新版的:Jmeter5.0入门介绍_第1张图片
  2. 修改中文显示菜单:在 apache-jmeter-5.0\bin下找到jmeter.properties文件Jmeter5.0入门介绍_第2张图片
  3. 打开jmeter.properties文件并修改如下 Jmeter5.0入门介绍_第3张图片
  4. 在 apache-jmeter-5.0\bin目录下找到 jmeter.bat双击并打开: 添加线程组:Jmeter5.0入门介绍_第4张图片
  5. 添加http请求                                            Jmeter5.0入门介绍_第5张图片
  6. 添加监听器:                                                  Jmeter5.0入门介绍_第6张图片
  7.  设置http请求                                                                                              Jmeter5.0入门介绍_第7张图片
  8.  设置线程数和执行次数                                                    Jmeter5.0入门介绍_第8张图片
  9.  HTTP请求测试的servlet代码: 
package com.bjsxt.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet(asyncSupported = true, description = "TestServlet", urlPatterns = { "/Test" })
public class TestServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	int i = 0; // 线程不安全
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		synchronized (this) { // 加锁 为了线程安全
			System.out.printf("%s:%s\n", Thread.currentThread().getName(), i);
			i++;
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.printf("%s:%s\n", Thread.currentThread().getName(), i);
		}
	}

}

 


 点击测试                                                               Jmeter5.0入门介绍_第9张图片

 后台打印结果

http-bio-8080-exec-3:0
http-bio-8080-exec-3:1
http-bio-8080-exec-4:1
http-bio-8080-exec-4:2
http-bio-8080-exec-6:2
http-bio-8080-exec-6:3
http-bio-8080-exec-8:3
http-bio-8080-exec-8:4
http-bio-8080-exec-10:4
http-bio-8080-exec-10:5
http-bio-8080-exec-2:5
http-bio-8080-exec-2:6
http-bio-8080-exec-5:6
http-bio-8080-exec-5:7
http-bio-8080-exec-7:7
http-bio-8080-exec-7:8
http-bio-8080-exec-9:8
http-bio-8080-exec-9:9
http-bio-8080-exec-1:9
http-bio-8080-exec-1:10
http-bio-8080-exec-2:10
http-bio-8080-exec-2:11
http-bio-8080-exec-4:11
http-bio-8080-exec-4:12

 

 

你可能感兴趣的:(Jmeter,线程安全,servlet)