您的位置:首页 > 编程语言 > Java开发

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

2018-04-01 15:12 417 查看
思路主要是通过模拟多个线程同时发起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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: