|
Introduction
| Servlets
& HTTP | Life-Cycle | Sessions
| Summary
| Examples Life Cycle: Loading | Servicing Requests | Threading | Reloading | |||||
Servlet ReloadingA servlet will be reloaded if its class file changes on disk and that class file is kept under the assigned servlet directory for that servlet engine. Every time a service request comes in for a servlet kept in the servlet directory, it's timestamp is checked and if it has been modified, it is reloaded. Servlet reloading is a useful programming aid that vastly reduces the edit/compile/test development cycle for servlets because there is no need to stop and start the web server. When you have finished testing your servlet, it should be taken out of the servlets directory and placed on the servlet engines CLASSPATH. In Java, anything on the CLASSPATH is loaded by the Primordial ClassLoader and loaded once. It is for this reason that the servlet directory is not on the servlet engine's CLASSPATH. The servlet directory is kept off the CLASSPATH so that servlet classes can be reloaded as and when they change, where classes on the CLASSPATH are loaded only once. For servlets in development, the servlet directory provides a pretty useful debug cycle, whilst for those in production, being on the CLASSPATH means that the servlet engine does not need to check their timestamps for every single service requests. Finally, it is recommended that you place shared classes on the CLASSPATH and not in the servlet directory. A shared class is one that is referenced or its instances used by multiple servlets and/or multiple instances of the same servlet. If a shared class resides in the servlet directory it is eligible for reloading. For example, if a servlet A references a shared class B, if A is reloaded it is highly likely that B will be reloaded as well. This gives rise to a number of scenarios where there can be multiple versions of the shared class B being referenced by multiple servlets and/or servlet instances. This leads to undefined behaviour within the servlet engine. To prevent shared classes from being reloaded, place shared classes on the CLASSPATH. Use Table 1 to determine whether your classes should be considered as shared.
| ||||||
(c) Zameer's Online Education 2006 |