Santosh Jadi Santosh Jadi - 2 years ago 243
Java Question

java.lang.IllegalStateException while reloading Tomcat Server

I'm working on Spring with Hibernate application, application is working fine but while starting or reloading tomcat server, i'm getting


Can anybody explain why this exception occurring and how to resolve it??

INFO: Illegal access: this web application instance has been stopped already. Could not load 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.
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at com.mysql.jdbc.SQLError.createLinkFailureMessageBasedOnHeuristics(
at com.mysql.jdbc.exceptions.jdbc4.CommunicationsException.<init>(
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(
at com.mysql.jdbc.SQLError.createCommunicationsException(
at com.mysql.jdbc.MysqlIO.send(
at com.mysql.jdbc.MysqlIO.quit(
at com.mysql.jdbc.ConnectionImpl.realClose(
at com.mysql.jdbc.ConnectionImpl.cleanup(
at com.mysql.jdbc.ConnectionImpl.finalize(
at java.lang.System$2.invokeFinalize(Unknown Source)
at java.lang.ref.Finalizer.runFinalizer(Unknown Source)
at java.lang.ref.Finalizer.access$100(Unknown Source)
at java.lang.ref.Finalizer$ Source)

Answer Source

I want to give you couple of choices. You can try it. Any option can fulfill your demand.

  1. Restart your tomcat and apache server because a long time of using, it keeps older version of your application.
  2. Clean your tomcat temp directory and restart
  3. As stated in error,

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.

It may be the real cause that at this moment you are in debugging mode and it doesn't clear the running thread. so remove your break point and run it not debugging

  1. If your code contains any kind of thread which are not properly terminated, then this type of error may occur. That you have init() method but no destroy() method, then this type of error may occur. For details, you can follow the link -

  2. if the webapp has stopped, or is stopping, that means that the .war file or WEB-INF/web.xml timestamp changed, and the webapp might be reloading. Please check timestamp is OK or not.

  3. To turn it off, set reloadable="false" in the context definition of your app. It might be tomcat's server.xml. In details solution: The tomcat's server.xml of the reloadable Context is set to false. For example:

Context path="/expert" docBase="expert" debug="0" reloadable ="false"/>

The solution is easy, as long as the tomcat's server.xml in reloadable = "true" into false on the line, but to do so would lose the advantage of hot deployment, and for the development is not very convenient, simply change it or not. This error does not matter.

Error principle:

The reason is because the tomcat restart, because the previous tomcat thread has not completely shut down, restart tomcat will report this exception, but this does not affect the normal use, just jump abnormal annoying people. Used hibernate, spring or other large components, when a WEB application system has a lot of class,

if you turned the Tomcat reloadable = true, then whenever the relevant documents change, Tomcat stops web app and frees up memory, and then reload web app. it may be a huge project. So we always think if there is only a certain class of overloaded functions, will greatly meet our debugger.

UPDATE: For code related issue

First, I want to tell you that I have given you some solutions for tomcat basis. Now I want to give you a solution for code basis. Would you please cross check your code with this issue? Please follow the URL.


UPDATE: For MySQL related issue

  1. There are 2 issues.

    • This web application instance has been stopped already. Could not load

    • This web application instance has been stopped already.Could not load com.mysql.jdbc.

This is because the MySQL JDBC driver on the application under the WEB-INF/lib directory, in the re-release of its loaded twice, so long as it can be copied to %TOMCAT_HOME%/lib can solve the problem. We can solve these two anomalies MySQL drivers from the WEB-INF/lib folder moved to %TOMCAT_HOME%/lib.

  1. I suspect this might be happening after the web application is restarted, where it's down for a short period of time. Then some finalize() method in the code is probably trying to do some cleanup too late. Whether or not that's in your code or the MySQL driver I can't say. You definitely should only have one version of a jar in a directory at a time. You might want to upgrade it to the latest (5.1.38 right now) in case something has been fixed that might be affecting you.(Number 9 is copied from @WhiteFang34)

Related link for 9: tomcat 6.0.24 Exception: Could not load com.mysql.jdbc.SQLError

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download