Hi!

> is there any way to get included servlets to dynamically reload?

I've been thinking about this problem, and I thought I would share it with you.

When Java needs a class, it asks its class loaders. Each loader (there can be many) is 
supposed to keep track of all classes it has loaded. If the loader has loaded the 
class, it is returned. If not, it tries to load and return it. If it fails, the VM 
goes on to the next class loader. If all fails, an Exception is thrown.

Since the class loader keeps the list of loaded classes, the class is always 
referenced once loaded, and won't be gc'd. The standard class loader can't be directed 
to drop it's references, at least not through the public API. You can check the docs 
for java.lang.ClassLoader for further details.

The JRun class loader for servlets, though, can discard it's loaded classes. I can't 
explain the exact flow of events, but it seems that when a call is made to the class 
as servlet, the age of the class in memory is compared to the age on the disk. This 
seems not to be done if the class is called any other way.

> i have all the class files in my web-inf/classes directory and if i go to
> the servlets directly they will dynamically reload to reflect changes, but
> if they are included in a jsp they will not.

This sums the behaviour up. So, what can you do to get dynamically reloaded classes?

1. You could write your own class loader, who checks this on every call to every 
class. Please note you'll need to have your classes in a directory _not_ served by any 
other class loader; keep this dir out of the classpath and the server dir. I haven't 
tried this, so I can't say how messy it will be.
2. Get yourself a servlet, who's sole point in life is to check the age and trigger 
the JRun reload of servlets. When you need a reload, touch the class file and call the 
servlet. Since the JRun class loader (last I checked, at least) throws out every class 
at the same time, all your classes would be refreshed. (At least this was the 
behaviour in JRun 2.2.1 - I haven't checked this on JRun 3).

///Yours, Jens Carlberg, Ericsson Sverige AB


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to