public class PressureTest implements Runnable {
private static long time = 0L;
private static final String URL = "www.baidu.com";
private static final int totalRequestCount = 100;
private static final int concurrentCount = 10;
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Thread thread = new Thread(new PressureTest());
thread.setName(i+"");
thread.start();
}
}
Thread.sleep(5000L);
System.out.println("平均响应时间:"+time/100);
}
@Override
public void run() {
long start = System.currentTimeMillis();
long end = 0L;
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("https://www.baidu.com").build();
try (Response response = client.newCall(request).execute()){
System.out.println(response.body().string());
end = System.currentTimeMillis();
} catch (IOException e) {
e.printStackTrace();
}
time += end - start;
System.out.println("响应时间:" + (end - start));
}
}
评论