Java多线程测试springboot的并发响应返回正确性

1.springboot的被测试函数

	/**
	 * 测试多线程返回
	 * @param request
	 * @param response
	 * @param jsonParam
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/api/test", method = RequestMethod.POST)
	public Object test(HttpServletRequest request, HttpServletResponse response, @RequestBody JSONObject jsonParam)
			throws Exception {
		Map<String, Object> requestmap = new HashMap<String, Object>();// 客户端原始请求数据
		Map<String, Object> resultmap = new HashMap<String, Object>();// 返回给客户端的结果		
		
		requestmap = JsonUtils.JsonToMapObj(jsonParam.toJSONString());
		int j = 0;
		for(int i=0;i<10000000;i++) {
			j = j + 1;
		}
		resultmap.put("threadNo", requestmap.get("threadNo"));
		return resultmap;
	}

通过比对上送和接收的threadNo是否一致来判断springboot并发返回的正确性

当中的循环模拟实际操作开销

2.线程类

package com.gg.lxz.test;

import java.util.HashMap;
import java.util.Map;

import com.gg.lxz.communication.http.GGHttpRequest;
import com.gg.lxz.utils.JsonUtils;

public class SubClass implements Runnable {
	
	private String threadNo;

	public void setThreadNo(String threadNo) {
		this.threadNo = threadNo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		GGHttpRequest request = new GGHttpRequest();
		String url = "http://127.0.0.1:16555/api/test";
		Map<String, Object> req = new HashMap<String, Object>();
		Map<String, Object> resp = new HashMap<String, Object>();
		req.put("threadNo", this.threadNo);
		resp = request.dopost(url, JsonUtils.MapToJson(req));
		resp.put("reqthreadNo", this.threadNo);
		System.out.println("response threadNo = "+resp);
	}

}

3.测试类 

		for (int i=0;i<500;i++){
			SubClass obj = new SubClass();
			obj.setThreadNo(new Integer(i).toString());
			Thread thread = new Thread(obj);
	        thread.start();
		}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值