tags:

views:

202

answers:

2

My build process builds and copies a .war file to $TOMCAT_HOME/webapps. 75% or more of the time, this works fine. But every now and then, the catalina.log file will show the following, and then all the apps deployed on Tomcat are totally stuck:

Oct 1, 2009 3:33:30 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/lucidity]
Oct 1, 2009 3:33:30 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive lucidity.war
Oct 1, 2009 3:33:32 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/Users/ptomblin/apache-tomcat-6.0.20/webapps/lucidity/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
Oct 1, 2009 3:33:32 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load java.net.BindException.  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:399)
    at com.mysql.jdbc.CommunicationsException.<init>(CommunicationsException.java:155)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2652)
    at com.mysql.jdbc.MysqlIO.quit(MysqlIO.java:1345)
    at com.mysql.jdbc.Connection.realClose(Connection.java:4784)
    at com.mysql.jdbc.Connection.cleanup(Connection.java:2040)
    at com.mysql.jdbc.Connection.finalize(Connection.java:3296)
    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.

Is there some other way I should be loading this WAR file into Tomcat?

A: 

Well, I don't use that particular Tomcat server any more, and when I load the WAR file to my self-hosted tomcat, it sometimes gives that exception, but then it tries again and eventually loads it. I have no idea why the other Tomcat was like it was, but the hosting company evidently did some changes to it.

Paul Tomblin
Do you use container connection pooling or handle the conneciton objects yourself?
Thorbjørn Ravn Andersen
@Thor - I don't know, I didn't write most of the code for this app.
Paul Tomblin
+1  A: 

Hi guys .. I got this problem . the main reason that there is a connection object for JDBC (I suppose its static ) ...so just close it and give it value null in ovverrided function finilizer() like this ( con refers to connection Obj. ) :

@Override

protected void finalize() throws Throwable {

        super.finalize();

        try{
             con.close();
             }catch(Exception r){
                  r.getMessage();
             }
             con=null;
    }

This solve my problem, but on the other hand I dont recommand to use connection as static never .. M.

Free_Palestine
You should fix it immediately. This way your webapp would only live for about half a hour until the DB decides to timeout and reclaim the connection. Always, always acquire *and* close connection, statement and resultset in the **shortest possible scope**, i.e. all inside the very same method block where the SQL is to be executed. Declare them outside try/finally block, acquire them in try block and close them in reversed order in finally block. For basic examples of correct JDBC code check this article: http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html
BalusC
the most efficient way to do this is by having the container do JDBC connection pooling.
Thorbjørn Ravn Andersen