Servlet Loading and Reloading

 < Free Open Study > 



We've looked at how the application classloaders of the container load the 'ordinary' classes that comprise a web application. But what of the servlet classes themselves? Although a servlet is a class like any other, we need to take extra care if the container supports servlet reloading.

For convenience during development some servers allow the redeployment of servlets on-the-fly, sometimes even by simply dropping them into a directory. The new versions are automatically reloaded by the server. However previous generations of servlet containers have handled servlet reloading by creating a new classloader to load the servlet, distinct from the classloaders used to load other servlets or classes. So once again, we can't be able to rely on values held in static variables.

To solve this problem, the Servlets 2.3 specification states:

start sidebar

"Although a Container Provider implementation of a class reloading scheme for ease of use is not required, any such implementation must ensure that all servlets, and the classes they use, are loaded in the scope of a single class loader."

end sidebar

One further issue to consider for servlets is not where they get loaded from, but when they get loaded into memory. We can:

  • Load servlets into memory when the application server starts up, which will increase the start-up time and use more memory.

  • Load servlets into memory at their first invocation. In this case servlets that are never invoked will never occupy memory and the server as a whole will start up quicker, but the first request to each servlet will be delayed.

This is a deployment issue that has no effect on how we code the servlets, but the impact on the performance of a web application could be significant.



 < Free Open Study > 



Professional Java Servlets 2.3
Professional Java Servlets 2.3
ISBN: 186100561X
EAN: 2147483647
Year: 2006
Pages: 130

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net