您的位置:首页 > 理论基础 > 计算机网络

TestHttp

2016-05-02 00:00 411 查看
摘要: 测试多线程访问。

测试多线程访问。

package com.asin;

import java.io.IOException;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;

public class TestHttp {

public static void main(String[] args) throws Exception {

final long t1 = System.currentTimeMillis();

for (int j = 0; j < 20; j++) {

for (int i = 0; i < 2000; i++) {
new Thread(new th()).start();
}

Thread.sleep(30000);
}
final long t2 = System.currentTimeMillis();
System.out.println(t2 - t1);
}
}

class th implements Runnable {

@Override
public void run() {

try {
HttpClients.createDefault().execute(new HttpGet(
"http://127.0.0.1:8080/xxx/002?countNumber=" + ((int) (Math.random() * 10) + 1)))
.close();

} catch (IOException e) {
e.printStackTrace();
}
}
}


用到的jar包:

commons-logging-1.1.3.jar

httpclient-4.3.1.jar

httpclient-cache-4.2.5.jar

httpcore-4.3.2.jar

httpmime-4.3.5.jar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: