所用版本asyncclient 4.1
代码: public static void main(String[] args) {
a();
}
public static void a(){
final CloseableHttpAsyncClient httpclient = ab();
String url ;
url="http://ww1w1.ffefdfdfdsdasdsdbafgfidugfligffdgfgee.com";
try {
httpclient.start();
HttpGet put=new HttpGet(url);
put.setHeader("Connection", "close");
httpclient.execute(put,
new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse result) {
System.out.println("1!");
try {
httpclient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("11");
}
public void failed(final Exception ex) {
System.out.println("2");
try {
httpclient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(5);
}
public void cancelled() {
System.out.println(3);
}
});
} catch (Exception ex) {
System.out.println("AAAAAAAAAAAsss");
try {
httpclient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static CloseableHttpAsyncClient ab()
{
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(100)
.setConnectionRequestTimeout(100)
.setSocketTimeout(1000)
//.setAuthenticationEnabled(false)
.build();
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setDefaultRequestConfig(requestConfig)
.build();
return httpclient;
}当返回时 failed时 请求无法关闭 断点走到httpclient.close() 时卡住 有知道是怎么回事的吗
代码: public static void main(String[] args) {
a();
}
public static void a(){
final CloseableHttpAsyncClient httpclient = ab();
String url ;
url="http://ww1w1.ffefdfdfdsdasdsdbafgfidugfligffdgfgee.com";
try {
httpclient.start();
HttpGet put=new HttpGet(url);
put.setHeader("Connection", "close");
httpclient.execute(put,
new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse result) {
System.out.println("1!");
try {
httpclient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("11");
}
public void failed(final Exception ex) {
System.out.println("2");
try {
httpclient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(5);
}
public void cancelled() {
System.out.println(3);
}
});
} catch (Exception ex) {
System.out.println("AAAAAAAAAAAsss");
try {
httpclient.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static CloseableHttpAsyncClient ab()
{
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(100)
.setConnectionRequestTimeout(100)
.setSocketTimeout(1000)
//.setAuthenticationEnabled(false)
.build();
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setDefaultRequestConfig(requestConfig)
.build();
return httpclient;
}当返回时 failed时 请求无法关闭 断点走到httpclient.close() 时卡住 有知道是怎么回事的吗
httpclient.close();在 close 之前 notifyAll 下,试试这样行不