"Steven J. Owens" wrote:
> I lost track of the attributions (I *think* Bill O'Keefe was the original
> poster), but essentially:
>
> >>On Thu, 24 Jun 1999, James Duncan Davidson wrote:
> >>>> I looked through the servlet spec, and didn't see any way to do
> >>>> this, but I just want to know for sure. Bascially, I'm looking
> >>>> for a way to reload a servlet without shutting down the web
> >>>> server. I don't want to use the dynamic reloading facility,
> >>>> since I don't
> >
> > >I think te original poster wants to load on demand a new version of the
> > >servlet's class - a method like:
> > >
> > > ServletContext.markObsolete(Servlet myservlet);
> > >
> > >in order to inform the context to reload (through class loader)
> > >when a new request comes.
> > >This opposed with expensive dynamic reloading provided by some web servers .
> > >
> > >There is no such method in JSDK.
> > >Cezar.
> >
> > Yes, this is basically what I wanted to do. Since there doesn't
> > appear to be such a method, do you have any idea how this could
> > be implemented? Or, it this basically something that would have
> > to be added to each servlet engine? Thanks,
>
> Depending on why you want to do this, couldn't you achieve much
> of the same effect by having the servlet instantiate and keep around a
> separate class to do all of the dirty work, then having some way of
> telling the servlet to throw away that class and reinstantiate it?
>
> I'm not sure how the library loading works in this case. I.e.
> given the following series of events:
>
> myservlet.class
> dirtywork.class <-- version 1
>
> start up servletengine
> servletengine loads in myservlet.class
> servletengine loads in dirtywork.class
> browser requests myservlet
> servletengine invokes myservlet.init
> myservlet.init calls myservlet.setupdirtywork
> mysevlet.setupdirtywork sets up dirtywork object
>
> overwrite dirtwork.class with new version
>
> poke myservlet.setupdirtywork somehow to get it to:
> throw away old dirtywork object
> reinstantiate dirtywork
>
> Does the servlet engine reload the class from disk or does it go
> with some cached version of dirtywork.class that's already in memory?
>
> Steven J. Owens
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
>
I also don't see a pressing need to do this at the servlet API level -- but letting
you manage your own dynamic reloading of worker classes, on the other hand, is a
pretty interesting idea.
You could implement this concept the same way that servlet engines do it -- by
using a custom class loader that supports automatic or on-demand reloading. Your
servlet would create its own class loader, and use it to create instances of the
"dirtywork" classes, and then reload them as desired. How this actually works is
that you throw away the class loader itself, which causes all the classes (and the
objects created with them) to be thrown away. Then, you can instantiate a new
class loader, and create new instances of objects using the new versions of the
classes themselves.
Apache JServ (http://java.apache.org) includes the source for the class loader it
uses to do the automatic servlet reloading trick
(org.apache.java.lang.AdaptiveClassLoader), and you could use this as the basis of
such a design. This class loader is also used by several other projects, including
the Locomotive application server (http://www.locomotive.org).
Because this implementation uses only standard Java APIs, it would be portable to
any servlet engine, without requiring the engine developers to modify anything.
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html