public void doGetTestOn1e() {
ExecutorService executorService = Executors.newFixedThreadPool(9999);
for (int i = 0; i < 999999; i++) {
executorService.execute(new RwdjThread());
}
}
/**
* GET---无参测试
*
* @date 2018年7月13日 下午4:18:50
*/
int index=0;
public void doGetTestOne() {
index++;
System.out.println(index);
// 获得Http客户端(可以理解为:你得先有一个浏览器;注意:实际上HttpClient与浏览器是不一样的)
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
// 创建Get请求
HttpGet httpGet = new HttpGet("http://192.168.228.21:8761/");
// 响应模型
CloseableHttpResponse response = null;
try {
// 由客户端执行(发送)Get请求
response = httpClient.execute(httpGet);
// 从响应模型中获取响应实体
HttpEntity responseEntity = response.getEntity();
// System.out.println("响应状态为:" + response.getStatusLine());
if (responseEntity != null) {
//System.out.println("响应内容长度为:" + responseEntity.getContentLength());
//System.out.println("响应内容为:" + EntityUtils.toString(responseEntity));
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
// 释放资源
if (httpClient != null) {
httpClient.close();
}
if (response != null) {
response.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private class RwdjThread implements Runnable{
private int wi;
/**
*
*/
public RwdjThread() {
super();
}
/**
* @param wi
*/
public RwdjThread(int wi) {
super();
this.wi = wi;
}
@Override
public void run() {
doGetTestOne();
}
}
多线程测试接口
最新推荐文章于 2024-03-07 07:15:00 发布