异常:
2013-1-15 15:27:34 org.apache.catalina.core.StandardContext reload
信息: Reloading this Context has started
2013-1-15 15:27:34 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/MapServer] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2013-1-15 15:27:34 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/MapServer] appears to have started a thread named [Timer-2] but has failed to stop it. This is very likely to create a memory leak.
2013-1-15 15:27:34 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/MapServer] created a ThreadLocal with key of type [org.apache.axis.utils.XMLUtils.ThreadLocalDocumentBuilder] (value [org.apache.axis.utils.XMLUtils$ThreadLocalDocumentBuilder@e9493a]) and a value of type [org.apache.xerces.jaxp.DocumentBuilderImpl] (value [org.apache.xerces.jaxp.DocumentBuilderImpl@1c6bbd3]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
2013-1-15 15:27:34 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
严重: The web application [/MapServer] created a ThreadLocal with key of type [org.apache.axis.utils.XMLUtils.ThreadLocalDocumentBuilder] (value [org.apache.axis.utils.XMLUtils$ThreadLocalDocumentBuilder@e9493a]) and a value of type [org.apache.xerces.jaxp.DocumentBuilderImpl] (value [org.apache.xerces.jaxp.DocumentBuilderImpl@554189]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.
2013-1-15 15:27:35 org.apache.catalina.loader.WebappClassLoader loadClass
信息: 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:1533)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1493)
at com.mysql.jdbc.SQLError.createLinkFailureMessageBasedOnHeuristics(SQLError.java:1276)
at com.mysql.jdbc.exceptions.jdbc4.CommunicationsException.<init>(CommunicationsException.java:58)
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( Util.java:411)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
at com.mysql.jdbc.MysqlIO.send( MysqlIO.java:3364)
at com.mysql.jdbc.MysqlIO.quit( MysqlIO.java:1708)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4371)
at com.mysql.jdbc.ConnectionImpl.cleanup( ConnectionImpl.java:1360)
at com.mysql.jdbc.ConnectionImpl.finalize(ConnectionImpl.java:2728)
at java.lang.ref.Finalizer.invokeFinalizeMethod( Native Method)
at java.lang.ref.Finalizer.runFinalizer(Unknown Source)
at java.lang.ref.Finalizer.access$100(Unknown Source)
at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source)
分析:
1. 在这新旧交替的时候,tomcat清掉旧的context,重建新的context,在旧的context中尚未来及终止的线程或者请求,必定会抛错。如果不想出这个错,可以禁用tomcat的自动reload,每次更新后,重启tomcat生效。
2. I found this explanation from web: It is possible that this is caused by Tomcat unsuccessfully reloading the web application. The app is unloaded, but all threads don't get shut down properly. As a result, when the threads try to run, they get clobbered by the fact that Tomcat has shut down its classloader, and an error is logged. The best fix is to turn off automatic webapp reloading for the application: in Tomcat's server.xml , find the <Context> declaration, and ensure it is set to: reloadable="false".
3. 在下面这段代码中
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->
</Host>
加入以下代码:
<Context path="/expert" docBase="expert" debug="0" reloadable="false">
本机上的例子:
<Host>
<Context docBase="F:\DEMO\Eclipse_J2EE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ROOT" path="" reloadable="false"/>
<Context docBase="F:\DEMO\Eclipse_J2EE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\C-PDMS2" path="/C-PDMS2" reloadable="true" source="org.eclipse.jst.jee.server:C-PDMS2"/>
<Context docBase="F:\DEMO\Eclipse_J2EE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\MapServer" path="/MapServer" reloadable="true" source="org.eclipse.jst.jee.server:MapServer"/>
</Host>
意义:
<Context>代表了运行在<Host>上的单个Web应用,一个<Host>可以有多个<Context>元素,每个Web应用必须有唯一的URL路径,这个URL路径在<Context>中的属性path中设定。
属性:
path:指定访问该Web应用的URL入口。
docBase:指定Web应用的文件路径,可以给定绝对路径,也可以给定相对于<Host>的appBase属性的相对路径,如果Web应用采用开放目录结构,则指定Web应用的根目录,如果Web应用是个war文件,则指定war文件的路径。
reloadable:如果这个属性设为true,tomcat服务器在运行状态下会监视在WEB-INF/classes和WEB-INF/lib目录下class文件的改动,如果监测到有class文件被更新的,服务器会自动重新加载Web应用。
总结:
在开发阶段将reloadable属性设为true,有助于调试servlet和其它的class文件,但这样用加重服务器运行负荷,建议在Web应用的发存阶段将reloadable设为false。