编程语言
首页 > 编程语言> > java 本地模拟高并发

java 本地模拟高并发

作者:互联网

通过http请求和多线程实现。
1、复写测试线程类,run方法中通过http请求进行模拟。

public class ThreadDemo implements Runnable {
    @Override
    public void run() {
        for (int i =0;i<10;i++){
            String url = "http://localhost:8080/aaa/test";
            HttpUtils.doGet(url);
        }
    }
}

2、模拟接口,for循环创建线程并且启用。

    @RequestMapping({"test1"})
    public ResponseModel test1() throws Exception {
        for(int i=0;i<50;i++){
            Thread aa = new Thread(new ThreadDemo());
            aa.start();
        }
        return null;
    }

3、在通过请求测试接口,去实现50路并发。

标签:test1,aa,java,ThreadDemo,int,并发,http,public,模拟
来源: https://blog.csdn.net/qq_34207422/article/details/122089582