Hi :-)  please see intermixed

Andrey Myatlyuk wrote:

> Hello Vladimir,
>
> Thank you for your help with classloaders. :)
>
> I tried to put my "shared" classes in the classpath. But this approach
> failed too. I cannot understand.
>
> In this case my "shared" classes loaded by "Bootstrap class loader
> (Java system classes)" and in case any references to them should use
> above classloader. Even in case servlet reloading. Of course, I removed
> these classes from web-inf/classes directory.

if you put your Helper class in CLASSPATH, I think it will be loaded by
System classloader -> not Bootstrap class loader, I think those "core Java
lib classes" will be loaded by Bootstrap class loader(for example,
java.lang.String)

and did you ever try the following to get the infomations of classloader?
  - (new String("haha")).getClass().getClassLoader().hashCode()
     it should be Bootstrap class loader

  - (new MySharedClass(...)).getClass().getClassLoader().hashCode()
     what is it? :-)

  - this.getServletContext().getClass().getClassLoader().hashCode()
     it should be System classloader

  - this.getClass().getClassLoader().hashCode()
    it should be webapp classloader

so we can know which classloader loads MySharedClass.


>
> May-be I need to load this "shared" class before loading my servlet, that uses
> this "shared" object? May-be it is loaded by "Webapp class loader
> (contents of WEB-INF/classes)"? I don't know.
>

I am not sure, but I guess perhaps the "loading order" is not important.

>
> This situation doesn't hurt me. I just want to know, how other Tomcat
> users deal with such problem. I think many projects use "shared"
> objects between servlets. This situation may be happen only in "development
> stage" and never in "production". But let me know, how do you deal
> with it?
>
> Wednesday, March 14, 2001, 7:10:01 PM, you wrote:
> [...]

I also think it is not important in most of the cases, because normally
we need to reload MyServlet Only in "development stage", but I just
guess in the following case:
   is it possible that when a Servlet container is very "busy", it will decide
   to unload-reload MyServlet even if I don't update MyServlet? I don't
   know, because I didn't find a detailed infomation  in Servlet spec2.2+
   do you know? thanks in advance! :-)



Bo
Mar.15, 2001


Reply via email to