Re: [Beanshell-users] howto clear global class definitions
Pat <
pat@...>
2004-03-04 17:01:19 GMT
On Thu, Mar 04, 2004 at 03:33:53PM +0100, Tim Plessers wrote:
> Hi Graham,
> Thanks for your quick reply.
> I looked into that mailinglist archive thread you suggested.
Hi Graham,
The current implementation in 2.0 b1 was a hack just to get something working.
It, as I think you saw, simply loads the classes in the system classloader.
This causes two problems: first, it's a security problem in some environments,
and second, no classloader will ever load a class twice.
If you look at how BeanShell implements its own classloaders for
setClassPath(), addClassPath() and reloadClasses() you'll see on example of
what can be done to work around this in the future.
What you have to do is load classes through a classloader that can be "thrown
away" when you want to load a new version.
So, one possibility would be to have our own classloader either load BeanShell
and everything it uses or possibly work with a context classloader that does
this. The bootstrap app has to have a few interfaces - whatever it needs to
interact with the interpreter - pulled out to its level and shared with the
child classloader. Then when you want to execute the script again you can
simply throw away the child classloader and create a new one.
Object instances created via classes defined in the old (tossed) classloader
can still hang around, and we can still use them because they stll implement
the common interfaces... They will simply prevent the classloader object
itself from being garbage collected.
(Continue reading)