I am reading Jason Hunter's JavaServlet Programming and I need some clarification on class loaders for servlet reloading. The author states that to prevent the ClassCastException "most server implementations now load each web application context within a single class loader and use a new class loader to reload the entire context when any servlet in the context changes." What is the purpose of using a new class loader? Why can't you simply use the original class loader again? After all you are going to reload the entire context. Any insight would be helpful.
posted 14 years ago
That's because the classloaders cache the currently loaded classes and do not provide an API to unload/reload the classes. In order to reload you must create a new classloader and then replace the current classloader with the new one, forcing classes to be re-read from disk (and thus picking up any new classes).
Karl Moss,<br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/007222262X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Java Servlets Developer's Guide</a> <br /><a href="http://www.servletguru.com" target="_blank" rel="nofollow">ServletGuru.com</a> the Companion site.
Tell me how it all turns out. Here is a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user