Invalid access: this web application instance is already stopped

I am developing an application with GWT, Hibernate (XML-based mapping), MySQL - in Tomcat6.0. IDE-Netbeans 6.9 I set the properties of the Deploy When Saving project in Netbeans.

When my application runs for a long time on the server, from time to time my application cannot connect to the database and throws the following exception

A possible next stack trace is caused by an error created for debugging purposes, as well as an attempt to terminate the thread, which resulted in 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.access$100(Finalizer.java:14) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160) 

When I restart my tomcat server, I can connect the database again. Please tell me how I can get smooth performance and can do this work without restarting tomcat.

+6
source share
1 answer

You are probably opening more and more connections and never closing them, and in the end you will reach the maximum number of connections to the database.

Find where you open connections, and make sure you close them. If you open a connection for each request but donโ€™t close it, itโ€™s easy to find and fix. Or you may not close the connection when you receive an error - check the exception handling code.

The recommended approach when using DB connections is to use try finally to make the most of your efforts when closing db connections:

 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); } } } 
+5
source

Source: https://habr.com/ru/post/895583/


All Articles