GVKun编程网logo

SimpleHttpConnectionManager使用不正确(simple connected)

15

本文将介绍SimpleHttpConnectionManager使用不正确的详细情况,特别是关于simpleconnected的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个

本文将介绍SimpleHttpConnectionManager使用不正确的详细情况,特别是关于simple connected的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect、apache HttpClient API中的setConnectionTimeout,setSoTimeout和“ http.connection- manager.timeout”之间有什么区别、Apache PoolingHttpClientConnectionManager引发非法状态异常、com.squareup.okhttp.internal.http.HttpURLConnectionImpl的实例源码的知识。

本文目录一览:

SimpleHttpConnectionManager使用不正确(simple connected)

SimpleHttpConnectionManager使用不正确(simple connected)

SimpleHttpConnectionManager使用不正确。确保始终调用HttpMethod.releaseConnection(),并且一次只有一个线程和/或方法正在使用此连接管理器。

是否有人知道为什么会出现此错误,并导致我要下载的文件失败或失败,然后重试或下载未完成的文件

谢谢 !

答案1

小编典典

确保不使用SimpleHttpConnectionManager创建和使用来自多个线程的连接。简单的连接管理器不是为它设计的-
它总是返回相同的连接,这不是线程安全的。

在多线程环境中,请使用使用连接池的其他管理器。请参见MultiThreadedHttpConnectionManager。

.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect

.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect

DEBUG 2016-11-07 14:32:47,518  Get connection for route {}->http://127.0.0.1:8087->http://rdsearch.zhaopin.com:80
DEBUG 2016-11-07 14:32:47,519  Connecting to 127.0.0.1:8087
DEBUG 2016-11-07 14:32:48,530  Connection org.apache.http.impl.conn.DefaultClientConnection@91161c7 closed
DEBUG 2016-11-07 14:32:48,531  Connection org.apache.http.impl.conn.DefaultClientConnection@91161c7 shut down
DEBUG 2016-11-07 14:32:48,532  Releasing connection org.apache.http.impl.conn.ManagedClientConnectionImpl@604ed9f0
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:117)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)

apache HttpClient API中的setConnectionTimeout,setSoTimeout和“ http.connection- manager.timeout”之间有什么区别

apache HttpClient API中的setConnectionTimeout,setSoTimeout和“ http.connection- manager.timeout”之间有什么区别

两者之间有什么区别(标记为评论):

MultiThreadedHttpConnectionManager connManag =  new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams managParams = connManag.getParams();

managParams.setConnectionTimeout(connectiontimeout); // 1
managParams.setSoTimeout(sotimeout); //2

HttpMethodBase baseMethod = null;

try {
  HttpClient client = new HttpClient(connManag);
  client.getParams().setParameter("http.connection-manager.timeout",poolTimeout); //3

  baseMethod = new GetMethod(…);
  int statusCode = client.executeMethod(…);

  …
}
catch (ConnectTimeoutException cte ){
  //Took too long to connect to remote host
}
catch (SocketTimeoutException ste){
  //Remote host didn’t respond in time
}
catch (Exception se){
  //Some other error occurred
}
finally {
  if (baseMethod != null)
    baseMethod.releaseConnection();
}

1. setConnectionTimeout -如果它确定在建立连接之前的超时。

2. setSoTimeout -如果确定两个连续数据包之间的不活动时间段或时间差,

那么下面的一个是做什么的:

3. "http.connection-manager.timeout"

Apache PoolingHttpClientConnectionManager引发非法状态异常

Apache PoolingHttpClientConnectionManager引发非法状态异常

这是我的用法-

private static final PoolingHttpClientConnectionManager connPool;static {        connPool = new PoolingHttpClientConnectionManager();        // Increase max total connection to 200        connPool.setMaxTotal(200);//configurable through app.properties        // Increase default max connection per route to 50        connPool.setDefaultMaxPerRoute(20);//configurable through app.properties}CloseableHttpClient httpClient = HttpClients.custom()                .setConnectionManager(connPool) .build();

另外,我在http GET周围放置了一个finally块-

finally {            try {                httpClient.close();            } catch (IOException e) {                LOGGER.error(e.getMessage());               }        }

这是我的堆栈跟踪-

java.lang.IllegalStateException: Connection pool shut down    at org.apache.http.util.Asserts.check(Asserts.java:34)    at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:169)    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:217)    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:157)    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)    at com.A.B.C.CustomHttpClient.doGETAndValidate(CustomHttpClient.java:44)    at com.A.B.C.SiteMonitorTask.monitorAndUpdateEndPoints(SiteMonitorTask.java:48)    at com.A.B.C.SiteMonitorTask.run(SiteMonitorTask.java:37)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)    at java.lang.Thread.run(Thread.java:744)

我正在使用Quartz计划监视Http端点的工作。这是我的连接池配置

totalMaxHttpConn=200maxHttpConnPerRoute=20

Maven依赖..工件版本

httpclient 4.3.1httpcore 4.3.1

编辑 -好吧,通过不关闭finally块中的CloseableHttpClient,问题解决了。有人能说出为什么这样吗?
如果关闭客户端,为什么连接池会关闭?

是上面的closeablehttpclient是池的句柄,而不是单个conn

答案1

小编典典

此行为是由于HC 4.3中的错误所致。它已在HC
4.4a1中修复。从4.4版本开始,CloseableHttpClient#close仅在客户端独占时才应自动关闭连接池

com.squareup.okhttp.internal.http.HttpURLConnectionImpl的实例源码

com.squareup.okhttp.internal.http.HttpURLConnectionImpl的实例源码

项目:LoRaWAN-Smart-Parking    文件:OkHttpClient.java   
HttpURLConnection open(URL url,Proxy proxy) {
  String protocol = url.getProtocol();
  OkHttpClient copy = copyWithDefaults();
  copy.proxy = proxy;

  if (protocol.equals("http")) return new HttpURLConnectionImpl(url,copy);
  if (protocol.equals("https")) return new HttpsURLConnectionImpl(url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:LoRaWAN-Smart-Parking    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:LoRaWAN-Smart-Parking    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,nor null
 * if the connection isn't using HTTPS. Since we permit redirects across
 * protocols (HTTP to HTTPS or vice versa),the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:smart-mirror-app    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:smart-mirror-app    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:smart-mirror-app    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:cordova-plugin-background-mode    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:cordova-plugin-background-mode    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:cordova-plugin-background-mode    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:multirotorstuff-vtx-calc    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:multirotorstuff-vtx-calc    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:multirotorstuff-vtx-calc    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:L.TileLayer.Cordova    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:L.TileLayer.Cordova    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:L.TileLayer.Cordova    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:cordova-android-tv    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:cordova-android-tv    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:cordova-android-tv    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:Cordova-Locale-Plugin    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:Cordova-Locale-Plugin    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:Cordova-Locale-Plugin    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:pubnub-rpi-smart-parking    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:pubnub-rpi-smart-parking    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:pubnub-rpi-smart-parking    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:IoTgo_Android_App    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:IoTgo_Android_App    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:IoTgo_Android_App    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:CanDoVS2015    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:CanDoVS2015    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:CanDoVS2015    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}
项目:krakn    文件:OkHttpClient.java   
HttpURLConnection open(URL url,copy);
  throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
项目:krakn    文件:Httpresponsecache.java   
private HttpEngine getHttpEngine(URLConnection httpconnection) {
  if (httpconnection instanceof HttpURLConnectionImpl) {
    return ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  } else if (httpconnection instanceof HttpsURLConnectionImpl) {
    return ((HttpsURLConnectionImpl) httpconnection).getHttpEngine();
  } else {
    return null;
  }
}
项目:krakn    文件:Httpresponsecache.java   
/**
 * Returns the SSL socket used by {@code httpconnection} for HTTPS,the implementation type of the
 * connection doesn't necessarily match the implementation type of its HTTP
 * engine.
 */
private SSLSocket getSslSocket(HttpURLConnection httpconnection) {
  HttpEngine engine = httpconnection instanceof HttpsURLConnectionImpl
      ? ((HttpsURLConnectionImpl) httpconnection).getHttpEngine()
      : ((HttpURLConnectionImpl) httpconnection).getHttpEngine();
  return engine instanceof HttpsEngine
      ? ((HttpsEngine) engine).getSslSocket()
      : null;
}

关于SimpleHttpConnectionManager使用不正确simple connected的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于.conn.ManagedClientConnectionImpl@604ed9f0 java.net.ConnectException: Connection refused: connect、apache HttpClient API中的setConnectionTimeout,setSoTimeout和“ http.connection- manager.timeout”之间有什么区别、Apache PoolingHttpClientConnectionManager引发非法状态异常、com.squareup.okhttp.internal.http.HttpURLConnectionImpl的实例源码的相关信息,请在本站寻找。

本文标签: