SimpleHttpConnectionManager being used incorrectly. Be sure that HttpMethod.releaseConnection() is always called and that only one thread

当前位置:

SimpleHttpConnectionManager being used incorrectly. Be sure that HttpMethod.releaseConnection() is always called and that only one thread

作者:邓华锋于2014-4-2发布在 分类:java / 阅读6969 次 / 共有0条评论  

Common HttpClient 工具包 执行GetMethod或PostMethod方法时,报如下信息提示:

SimpleHttpConnectionManager being used incorrectly. Be sure that HttpMethod.releaseConnection() is always called and that only one thread and/or method is using this connection manager at a time.


原因是上一个HttpMethod方法未关闭,就又执行了HttpMethod的方法导致。

例如以下形式:

GetMethod getMethod1 = new GetMethod(uri1);

GetMethod getMethod2 = new GetMethod(uri2);

getMethod2.releaseConnection();

getMethod1.releaseConnection();

有时会报以上信息提示,

规范的形式如以下,用完HttpMethod就关闭,如果要获取网页内容,在关闭前获取并存在临时变量里,以便后面操作用:

GetMethod getMethod1 = new GetMethod(uri1);

getMethod1.releaseConnection();

GetMethod getMethod2 = new GetMethod(uri2);

getMethod2.releaseConnection();