this web application instance has been stopped
already
TongWeb 日志报错如下:
java.lang.IllegalStateException: Illegal access:this web application instance has been stopped already. Could not
load [redis.clients.util.Pool]. The following stack trace is thrown for debugging purposes as well as to attempt to
terminate the thread which caused the illegal access.
问题原因:应用经常会启动一些端口或线程,在应用服务器上卸载、反复部应用时,若应用代码写的不规范,就不能
正常停止应用建的端口和线程,导致应用卸载不干净。
正确的方法为:在 listener 或 servlet 的 destory 中停止应用启动的端口或线程,这样应用服务器在卸载应用时,会调用
listener 或 servlet 的 destory 方法,从而可以销毁应用创建的资源。而很多应用却忽略了这一点。
如:重写 listener contextDestroyed 方法,该卸载的卸载。
public void contextDestroyed(ServletContextEvent arg0) {
//停止应用的端口
//停止应用的线程
}
#重写 servlet destroy()方法
public void destroy() {
//停止应用的端口
//停止应用的线程
}
同时引申出另外一个问题:在不重启 TongWeb 的情况下,能否重部署应用实时生效?
答:实际场景下往往不能这样用,原因同上,很多应用不在卸载时执行卸载操作。
若重部署应用不重启 TongWeb 通常会引发以下三类问题:
(1)容易导致内存溢出,报错如下:
#JDK7 及以下
OutOfMemoryError:PermGenspace
#JDK8 及以上
OutOfMemoryError:Metaspace
(2)应用启动的端口占用报错:addresshasbeenused。