I think there is a problem with ContextClassLoaderInterceptor; when the
embedded tomcat service starts and existing contexts are initialized, the
tomcat context class loaders get linked together in a complex (and broken!
way).

In ContextClassLoaderInterceptor.contextInit in the current version (1.5
according to CVS), the contextInit method is:

  public void contextInit( Context context) 
      throws TomcatException 
   {
      
((AdaptiveClassLoader)context.getServletLoader().getParentLoader()).setParent(Thread.currentThread().getContextClassLoader());
      
Thread.currentThread().setContextClassLoader(((ClassLoader)context.getServletLoader().getClassLoader()));
   }

This sets the parent loader of the servlet context just fine, but leaves the
context class loader changed.

Existing tomcat contexts are initialized one by one and this leaves the tomcat
context class loaders all chained together, which leads to some very strange
effects.

The ideal solution might be to modify the Tomcat ContextManager class to reset
the thread context class loader after each context is initialised.  I wanted
to avoid changing tomcat so the only solution I could find was to modify
ContextClassLoaderInterceptor:

public class ContextClassLoaderInterceptor 
   extends BaseInterceptor 
{ private ClassLoader baseLoader;

    // Store initial context loader

    public void engineInit(ContextManager cm) throws TomcatException {
      baseLoader = Thread.currentThread().getContextClassLoader();
    }

    public void contextInit( Context context) 
      throws TomcatException 
   {

     // Now try to avoid chained loaders!

     ClassLoader tcl = Thread.currentThread().getContextClassLoader();
     ((AdaptiveClassLoader)context.getServletLoader().getParentLoader()).setParent(tcl 
instanceof AdaptiveClassLoader ? baseLoader : tcl);

     
Thread.currentThread().setContextClassLoader(((ClassLoader)context.getServletLoader().getClassLoader()));
   }

}

Here contextInit sets the parent loader to the initial base loader if the
context loader is already an AdaptiveClassLoader.

Hope this makes sense!

Richard Evans
Retek


_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to