Sam Heisz wrote:
> I am fairly new to the list, and first I want to thank Kevin, Craig, Daniel,
> and everyone else who contributed to the Model 2 discussion.
>
> One question I have: is there any way to explicitly cause an Action class to
> be unloaded, so that a newly compiled version will be loaded in its place?
> It seems painstaking to have to restart the server every time an action
> class is changed.
>
In some servlet containers, the web application is restarted if *any* class (or any
class underl WEB-INF/classes and WEB-INF/lib) is changed, not just servlet
classes. You might want to double check what the rules are on yours.
>
> I realize that there are some multi-threading issues, I can take care of
> those, guranteeing that no actions are in use or referenced from anywhere at
> a certain point, but how do I get the class unloaded?
> System.gc() doesn't gurantee anything.
>
Multi-threading issues are actually the easiest piece of this problem two solve.
The bigger problem is the limited support that the Java language gives you for
reloading classes. Basically, you have to use a custom class loader, and then
throw away that class loader (and all the classes and instances it created) to load
a new one. There are lots of subtle issues with class cast errors that you have to
watch out for (com.mycompany.Foo loaded by one class loader instance is *not* the
same class as com.mycompany.Foo loaded by a different one).
Servlet containers that implement auto-reload typically do it by unloading and
restarting the entire application. Sessions that were active at the time may or
may not be saved, depending on the features of your servlet container. Trying to
do this on a class-by-class basis is going to be problematic.
By the way, JSP pages get around this problem by "cheating" -- each time the page
is changed and recompiled, it is given a new class name by the page compiler, so it
doesn't need to worry about reloading the same class again. That's probably not an
option for your Model 2 based controller servlet, unless you want to get really
fancy in the way you map requests to action class names.
>
> Thanks,
>
> Sam
>
Craig McClanahan
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets