java 非法访问:此 Web 应用程序实例已被停止
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7147181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Illegal access: this web application instance has been stopped already
提问by Amandeep Singh
I am developing an application with GWT, Hibernate(XML based mapping), MySQL- in Tomcat6.0. IDE- Netbeans 6.9 I set the project properties "Deploy On Save" option in Netbeans.
我正在使用 GWT、Hibernate(基于 XML 的映射)、MySQL-在 Tomcat6.0 中开发一个应用程序。IDE- Netbeans 6.9 我在 Netbeans 中设置了项目属性“保存时部署”选项。
When my application is running for long time in server every now and then my application fails to connect to database and throws the following exception
当我的应用程序在服务器中长时间运行时,我的应用程序无法连接到数据库并抛出以下异常
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:1273)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4273)
at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1444)
at org.hibernate.connection.DriverManagerConnectionProvider.close(DriverManagerConnectionProvider.java:152)
at org.hibernate.connection.DriverManagerConnectionProvider.finalize(DriverManagerConnectionProvider.java:142)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access0(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
When I restart my tomcat server I am again able to connect the Database.Please tell me the way through which I can get seamless performance and can get the work done without restarting the tomcat.
当我重新启动我的 tomcat 服务器时,我再次能够连接数据库。请告诉我如何获得无缝性能并可以在不重新启动 tomcat 的情况下完成工作。
采纳答案by Bohemian
You are probably opening more and more connections and never closing them, eventually reaching your database's configured maximum connection count.
您可能正在打开越来越多的连接并且从不关闭它们,最终达到数据库配置的最大连接数。
Find where you are opening connections and make sure you are closing them. If you open a connection for every request but don't close it, that's easy to find and fix. Or you might not be closing you connection when you get an error - check your exception handling code.
找到打开连接的位置并确保关闭它们。如果您为每个请求打开一个连接但不关闭它,则很容易找到并修复它。或者,您可能不会在收到错误时关闭连接 - 检查您的异常处理代码。
The recommended approach when using DB connections is to use a try finally
to make a best effort at closing db connections:
使用数据库连接时推荐的方法是使用 atry finally
尽最大努力关闭数据库连接:
Connection con;
try {
con = ...; // open connection
// do work
catch (SQLException e) {
// do whatever
} finally {
if (con != null && !con.isClosed()) {
try {
con.close();
catch (SQLException e) {
// Don't throw from here or you'll lose any return/exception from above
log.error("Failed to close connection", e);
}
}
}