Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal access: this web application instance has been stopped already

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.

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.access$100(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.

like image 663
Amandeep Singh Avatar asked Aug 22 '11 12:08

Amandeep Singh


1 Answers

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:

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);
        }
    }
}
like image 199
Bohemian Avatar answered Oct 27 '22 02:10

Bohemian