public class Main { public static void main(String[] args) throws Exception {
// Create and initialize HTTP parameters
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(params, 100);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm, params); // create an array of URIs to perform GETs on
String[] urisToGet = {
"http://www.baidu.com",
"http://www.sohu.com"
}; // create a thread for each URI
GetThread[] threads = new GetThread[urisToGet.length];
try{
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new GetThread(httpClient, httpget, i + 1);
}// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}// join the threads
for (int j = 0; j < threads.length; j++) {
threads[j].join();
}
}finally {
httpClient.getConnectionManager().shutdown();
}
} /**
* A thread that performs a GET.
*/
public static class GetThread extends Thread { private final HttpClient httpClient;
private final HttpContext context;
private final HttpGet httpget;
private final int id; public GetThread(HttpClient httpClient, HttpGet httpget, int id) {
this.httpClient = httpClient;
this.context = new BasicHttpContext();
this.httpget = httpget;
this.id = id;
} /**
* Executes the GetMethod and prints some status information.
*/
@Override
public void run() { System.out.println(id + " - about to get something from " + httpget.getURI()); try {
HttpResponse response = httpClient.execute(httpget, context);
System.out.println(id + ":" +response.getStatusLine());
} catch (Exception e) {
httpget.abort();
System.out.println(id + " - error: " + e);
}
}
}
}上面红色的部分,怎么在jsp页面上显示出来啊,我是新手,最好有写出代码,谢谢了!!!
// Create and initialize HTTP parameters
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(params, 100);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm, params); // create an array of URIs to perform GETs on
String[] urisToGet = {
"http://www.baidu.com",
"http://www.sohu.com"
}; // create a thread for each URI
GetThread[] threads = new GetThread[urisToGet.length];
try{
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new GetThread(httpClient, httpget, i + 1);
}// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}// join the threads
for (int j = 0; j < threads.length; j++) {
threads[j].join();
}
}finally {
httpClient.getConnectionManager().shutdown();
}
} /**
* A thread that performs a GET.
*/
public static class GetThread extends Thread { private final HttpClient httpClient;
private final HttpContext context;
private final HttpGet httpget;
private final int id; public GetThread(HttpClient httpClient, HttpGet httpget, int id) {
this.httpClient = httpClient;
this.context = new BasicHttpContext();
this.httpget = httpget;
this.id = id;
} /**
* Executes the GetMethod and prints some status information.
*/
@Override
public void run() { System.out.println(id + " - about to get something from " + httpget.getURI()); try {
HttpResponse response = httpClient.execute(httpget, context);
System.out.println(id + ":" +response.getStatusLine());
} catch (Exception e) {
httpget.abort();
System.out.println(id + " - error: " + e);
}
}
}
}上面红色的部分,怎么在jsp页面上显示出来啊,我是新手,最好有写出代码,谢谢了!!!
解决方案 »
- ssh博客项目的一个功能问题
- jsp怎么处理才能显示中文,输出的都是问号,怎么办?
- 求助:如何在resin下使用jndi配置proxool的连接池啊
- javaw.exe占用内存大
- 这个东东,有人知道吗,谢谢大家了
- servlet中如何自动跳到一个jsp页面?
- 抛开页面逻辑和显示这个不说,大家认为直接在每个页面中写数据库连接的代码的页面执行效率高,还是用一个数据库连接bean的效率高?连接池
- 将新闻的所有字段存入索引检索工具中,还是只存一部分?
- 差不多等于白送分的ORACLE查询问题!!谢谢了兄弟们,在线等.
- 请教关于tomcat根目录的问题
- 关于jboss的login-config.xml的配置文件
- 求指点.....chrome浏览器怎么查看链接地址..
response.getWriter().print(id + ":" +response.getStatusLine());)