这样URL Connection能否及时释放
long hash = jHash.hash(("info:" + domain).getBytes());
String url = "http://"+GOOGLE_PR_DATACENTER_IPS[index-1]+"/search?client=navclient-auto&hl=en&"+
"ch=6"+hash+"&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + domain;
InputStream is = null;
URLConnection con = null;
try {
//proxy网络代理
if (proxy == null) {
con = new URL(url).openConnection();
} else {
con = new URL(url).openConnection(proxy);
}
con.setConnectTimeout(30000); //设置连接超时时间
is = con.getInputStream(); //获取数据流
byte [] buff = new byte[1024];
int read = is.read(buff);
while (read > 0) {
googlePrResult = new String(buff, 0, read);
read = is.read(buff);
}
googlePrResult = googlePrResult.split(":")[2].trim();
result = new Long(googlePrResult).intValue();
} catch (Exception e) {
result = -1;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
long hash = jHash.hash(("info:" + domain).getBytes());
String url = "http://"+GOOGLE_PR_DATACENTER_IPS[index-1]+"/search?client=navclient-auto&hl=en&"+
"ch=6"+hash+"&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + domain;
InputStream is = null;
URLConnection con = null;
try {
//proxy网络代理
if (proxy == null) {
con = new URL(url).openConnection();
} else {
con = new URL(url).openConnection(proxy);
}
con.setConnectTimeout(30000); //设置连接超时时间
is = con.getInputStream(); //获取数据流
byte [] buff = new byte[1024];
int read = is.read(buff);
while (read > 0) {
googlePrResult = new String(buff, 0, read);
read = is.read(buff);
}
googlePrResult = googlePrResult.split(":")[2].trim();
result = new Long(googlePrResult).intValue();
} catch (Exception e) {
result = -1;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货