New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultApacheHttpClientBuilder总是报错? #285

Closed
qinggee opened this Issue Jul 20, 2017 · 16 comments

Comments

Projects
None yet
5 participants
@qinggee

qinggee commented Jul 20, 2017

不知道为什么?
DefaultApacheHttpClientBuilder的以下代码位置总是报错。
@Override public void run() { try { while (!this.shutdown) { synchronized (this) { wait(this.checkWaitTime); this.connMgr.closeExpiredConnections(); this.connMgr.closeIdleConnections(this.idleConnTimeout, TimeUnit.MILLISECONDS); } } } catch (InterruptedException ignore) { } }

信息: Illegal access: this web application instance has been stopped already. Could not load org.apache.http.pool.AbstractConnPool$4. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.http.pool.AbstractConnPool.closeExpired(AbstractConnPool.java:558)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.closeExpiredConnections(PoolingHttpClientConnectionManager.java:409)
at me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder$IdleConnectionMonitorThread.run(DefaultApacheHttpClientBuilder.java:302)

DEBUG 2017-07-20 14:40:59,462 org.apache.http.impl.conn.PoolingHttpClientConnectionManager: Closing expired connections

@qinggee

This comment has been minimized.

qinggee commented Jul 20, 2017

能否进行解答?谢谢。

@kakotor

This comment has been minimized.

kakotor commented Jul 20, 2017

什么情况下会报这个错误

@qinggee

This comment has been minimized.

qinggee commented Jul 22, 2017

在eclipse中,通过debug模式运行web项目,这段代码就会在后台不停的运行。如果Tomcat自动重启一次,这段代码就开始不停的报错,提示stopped,但项目本身还是可以正常运行的。

抱歉,不知道是否能表达清楚,如果你本地有环境的话,重复一次到两次,这个错误就会不停出现。

@binarywang

This comment has been minimized.

Member

binarywang commented Jul 31, 2017

感觉没表达清楚,本地没遇到过此问题

@kakotor

This comment has been minimized.

kakotor commented Jul 31, 2017

大概明白是什么意思了,如果不是tomcat自动重启会报错么?
错误是自动重启后出错,可能是因为类卸载加载出问题,具体的要看tomcat的类重载过程。
这里是启动了一个守护线程,定时的清理超时的链接。
也可以自己实现一下ApacheHttpClientBuilder

P.S. 不推荐使用tomcat的自动重载功能,最好还是关闭再重启。开发环境为了节省时间建议使用JRebel

@tomsean

This comment has been minimized.

tomsean commented Aug 3, 2017

DefaultApacheHttpClientBuilder里面的写法方式会造成线程无法回收,这个类最好修改调整下。

@kakotor

This comment has been minimized.

kakotor commented Aug 3, 2017

DefaultApacheHttpClientBuilder按道理这个类应该是保持单例的
里面的守护线程确实存在多例的时候无法回收的问题
有时间尝试改为单例或者您也可以提交一个pr改造一下

@qinggee

This comment has been minimized.

qinggee commented Aug 5, 2017

能力有限,发现问题但还没有解决问题的能力,一直就这么将就着用,Tomcat自动重启惯了,只要一自动重启,就会报错,报错后就把Tomcat关了,感觉真的不好,关键是自己还写不来改造的方法。希望有高手可以改造一个出来。

@binarywang

This comment has been minimized.

Member

binarywang commented Aug 10, 2017

@jlions

This comment has been minimized.

jlions commented Aug 12, 2017

我的也报错了,用好久了,之前一直正常的,今天突然报错了, 项目启动时间达到7m,之前是不到30s

@kakotor

This comment has been minimized.

kakotor commented Aug 14, 2017

@jlions 错误内容是什么呢?

@qinggee

This comment has been minimized.

qinggee commented Aug 14, 2017

@binarywang ,恩,不过,tomcat内部debug自动重启的时候依然会报错。

DEBUG 2017-08-14 10:48:23,064 org.apache.http.impl.conn.PoolingHttpClientConnectionManager: Closing expired connections
八月 14, 2017 10:48:23 上午 org.apache.catalina.loader.WebappClassLoader loadClass
信息: Illegal access: this web application instance has been stopped already.  Could not load org.apache.http.pool.AbstractConnPool$4.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
	at org.apache.http.pool.AbstractConnPool.closeExpired(AbstractConnPool.java:558)
	at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.closeExpiredConnections(PoolingHttpClientConnectionManager.java:409)
	at me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder$IdleConnectionMonitorThread.run(DefaultApacheHttpClientBuilder.java:313)

DEBUG 2017-08-14 10:49:22,448 org.apache.http.impl.conn.PoolingHttpClientConnectionManager: Closing expired connections
DEBUG 2017-08-14 10:49:22,475 org.apache.http.impl.conn.PoolingHttpClientConnectionManager: Closing connections idle longer than 60000 MILLISECONDS

错误的栈为以下这段代码:

    @Override
    public void run() {
      try {
        while (!this.shutdown) {
          synchronized (this) {
            wait(this.checkWaitTime);
            this.connMgr.closeExpiredConnections();
            this.connMgr.closeIdleConnections(this.idleConnTimeout,
              TimeUnit.MILLISECONDS);
          }
        }
      } catch (InterruptedException ignore) {
      }
    }
@kakotor

This comment has been minimized.

kakotor commented Aug 14, 2017

因为没有环境,没办法测试你这个问题
你可以尝试在
DefaultApacheHttpClientBuilder#223行下添加如下代码 测试一下
Runtime.getRuntime().addShutdownHook(new Thread(){
@override
public void run() {
idleConnectionMonitorThread.shutdown();
}
});
方便的话可以直接提交pr 或给个反馈我来提交

@jlions

This comment has been minimized.

jlions commented Aug 14, 2017

@binarywang

This comment has been minimized.

Member

binarywang commented Aug 15, 2017

如果是debug自动重启的问题,我觉得可以忽略掉,毕竟只是开发模式才出现的,而且也不会影响实际功能 @qinggee

@binarywang

This comment has been minimized.

Member

binarywang commented Aug 23, 2017

暂时关闭,至于kakotor提到的办法,如果有人验证过没问题的话请提交PR。

@binarywang binarywang closed this Aug 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment