Illegal access: this web application instance has been stopped already

20,158

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);
        }
    }
}
Share:
20,158
Amandeep Singh
Author by

Amandeep Singh

I am a technology enthusiast and work on improving solutions across. Currently also working on a hobby projects: zgrepcode mobilenumbertracker

Updated on March 07, 2020

Comments

  • Amandeep Singh
    Amandeep Singh over 4 years

    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.

  • SJuan76
    SJuan76 almost 13 years
    IMHO, if that was the case, I would expect an error 500 and not the one that is reported. In fact Servlets that do not need DB connection should be still working.
  • SJuan76
    SJuan76 almost 13 years
    Then look for Bohemian's solution (yet I still think it is a pretty much missleading message...)
  • Amandeep Singh
    Amandeep Singh almost 13 years
    I think this had worked out for me thanks all for the replies and comments