0
点赞
收藏
分享

微信扫一扫

用Java代码简单模拟并发访问


思路主要是通过模拟多个线程同时发起http请求。

public class TestBingfa {
//发送请求的url地址
private final String url = "http://localhost:8085/bda-search";
//模拟的并发量
private static final int BINGFA = 199;

private static CountDownLatch cdl = new CountDownLatch(BINGFA);

public static void main(String[] args) {
for (int i = 0; i < BINGFA; i++) {
new Thread(new UserRequest()).start();
cdl.countDown();
}
}

public static class UserRequest implements Runnable{
@Override
public void run() {
try {
cdl.await();
} catch (Exception e) {
e.printStackTrace();
}
//使用工具类发送http请求
String json2 = HttpClientUtil.sendHttpPostJson(url, getJson());
System.out.println(new Date().getTime()+"::"+json2);
}

}

//发送的请求参数
public static String getJson(){
return null;
}
}

举报

相关推荐

0 条评论