+-----------------------------+<!-- comment these out if you want to see an example of custom fields, but remember to name the fields
in the same way they are named here: 'imfeeling' (livejournal.com style), 'listening' and 'new_field'
<p>
<br />
<b>:</b> <br />
?
</p>
--> 3 - 部分原代码分析
在一个JVM中可能存在多个ClassLoader,每个ClassLoader拥有自己的NameSpace。一个ClassLoader只能拥有一个class对象类型的实例,但是不同的ClassLoader可能拥有相同的class对象实例,这时可能产生致命的问题。如ClassLoaderA,装载了类A的类型实例A1,而ClassLoaderB,也装载了类A的对象实例A2。逻辑上讲A1=A2,但是由于A1和A2来自于不同的ClassLoader,它们实际上是完全不同的,如果A中定义了一个静态变量c,则c在不同的ClassLoader中的值是不同的。
<!-- comment these out if you want to see an example of custom fields, but remember to name the fields
in the same way they are named here: 'imfeeling' (livejournal.com style), 'listening' and 'new_field'
<p>
<br />
<b>:</b> <br />
?
</p>
-->
| Bootstrap |
| | |
| System |
| | |
| Common |
| / |
| Catalina Shared |
| / |
| WebApp1 WebApp2 |
+-----------------------------+
其中:
- Bootstrap - 载入JVM自带的类和$JAVA_HOME/jre/lib/ext/*.jar
- System - 载入$CLASSPATH/*.class
- Common - 载入$CATALINA_HOME/common/...,它们对TOMCAT和所有的WEB APP都可见
- Catalina - 载入$CATALINA_HOME/server/...,它们仅对TOMCAT可见,对所有的WEB APP都不可见
- Shared - 载入$CATALINA_HOME/shared/...,它们仅对所有WEB APP可见,对TOMCAT不可见(也不必见)
- WebApp? - 载入ContextBase?/WEB-INF/...,它们仅对该WEB APP可见
由此可得:
- 对于WEB APP线程,它的contextClassLoader是WebApp?ClassLoader
- 对于Tomcat Server线程,它的contextClassLoader是CatalinaClassLoader <!-- comment these out if you want to see an example of custom fields, but remember to name the fields
in the same way they are named here: 'imfeeling' (livejournal.com style), 'listening' and 'new_field'
<p>
<br />
<b>:</b> <br />
?
</p>
-->