测试多线程访问。
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