本人使用httpclient框架编写了一段代码,用来模拟提交一个http请求,JavaIDE使用的是Myeclipse5.5,httpclient版本为3.1:
commons-httpclient-3.1.jar;
commons-codec-1.3.jar;
commons-logging.jar; 我的代码主要框架如下: import java.io.*;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.HttpStatus; public static String GetUserInfo(String host, String id, String appUri) throws IOException {
if (host.length() < 9 | | id.length() <= 0 | | appUri.length() <= 0) {
return null;
} // 准备httppoost
PostMethod post = new PostMethod(host); // 组织数据
StringBuffer buffer = new StringBuffer();
buffer.append(" <id>");
buffer.append(id);
buffer.append(" </id>");
buffer.append(" <uri>");
buffer.append(appUri);
buffer.append(" </uri>"); // 组织请求实例
RequestEntity entity = new StringRequestEntity(buffer.toString(), "text/xml", "ISO-8859-1");
post.setRequestEntity(entity); // 实例http连接
HttpClient httpclient = new HttpClient();
String info = null; try {
int result = httpclient.executeMethod(post);
int code = post.getStatusCode();
if (code == HttpStatus.SC_OK) {
info = new String(post.getResponseBodyAsString());
} catch (IOException ex) {
ex.printStackTrace();
} finally {
post.releaseConnection();
} return info;
}
测试该程序时,使用Myeclips默认的JVM,程序执行时间大概为300毫秒,但是换成BEA的jrockit90_150_04后运行时间变得非常慢,为5秒以上。
请问这可能是什么原因啊?是不是jrockit有什么特别之处?有什么解决办法吗?
谢谢!
commons-httpclient-3.1.jar;
commons-codec-1.3.jar;
commons-logging.jar; 我的代码主要框架如下: import java.io.*;
import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.HttpStatus; public static String GetUserInfo(String host, String id, String appUri) throws IOException {
if (host.length() < 9 | | id.length() <= 0 | | appUri.length() <= 0) {
return null;
} // 准备httppoost
PostMethod post = new PostMethod(host); // 组织数据
StringBuffer buffer = new StringBuffer();
buffer.append(" <id>");
buffer.append(id);
buffer.append(" </id>");
buffer.append(" <uri>");
buffer.append(appUri);
buffer.append(" </uri>"); // 组织请求实例
RequestEntity entity = new StringRequestEntity(buffer.toString(), "text/xml", "ISO-8859-1");
post.setRequestEntity(entity); // 实例http连接
HttpClient httpclient = new HttpClient();
String info = null; try {
int result = httpclient.executeMethod(post);
int code = post.getStatusCode();
if (code == HttpStatus.SC_OK) {
info = new String(post.getResponseBodyAsString());
} catch (IOException ex) {
ex.printStackTrace();
} finally {
post.releaseConnection();
} return info;
}
测试该程序时,使用Myeclips默认的JVM,程序执行时间大概为300毫秒,但是换成BEA的jrockit90_150_04后运行时间变得非常慢,为5秒以上。
请问这可能是什么原因啊?是不是jrockit有什么特别之处?有什么解决办法吗?
谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货