Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class reloader question

 
Bob Young
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading Jason Hunter's Java Servlet 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.
 
Karl Moss
Author
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
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
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!