tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bir...@ca.ibm.com
Subject Embedded Tomcat and ClassLoader's
Date Tue, 30 Jul 2002 14:55:06 GMT
Hi,

I'd appreciate any thoughts on the following (am I changing Tomcat code in
an acceptable way, or is there another solution like subclassing, etc. to
do what I want?):

I am using the Embedded class to run Tomcat in my Java application
(Eclipse) and need to control the compilation/running of JSP's in a dynamic
way:
all the requests to JSP's go to a dispatcher servlet that creates a class
loader based on the JSP path, sets it on the current Thread context and
redirect to the JspServlet to process the request. Since the Thread context
class loader was set by me, I expect that JspServlet to be run in the same
request thread and use that class loader.

This only works if I make two simple modifications to the Tomcat code, in
ApplicationDispatcher and JspServlet, and I wonder if these change have any
"bad" side effects:

org.apache.catalina.core.ApplicationDispatcher.invoke() :
-------------------------------------------------------------------------------------

It looks like the current Tomcat code is chaning the Thread context class
loader to always be the webapp class loader. Can I safely comment out the
following code (and the matching one at the end of the invode() method) ?
Basically, I want that the class loader set on the Thread context to be the
one used, even though it will not be the same as the webapp class loader.

        ClassLoader oldCCL = Thread.currentThread().getContextClassLoader
();
        ClassLoader contextClassLoader = context.getLoader().getClassLoader
();

        if (oldCCL != contextClassLoader) {
            Thread.currentThread
().setContextClassLoader(contextClassLoader);
        } else {
            oldCCL = null;
        }


org.apache.jasper.servlet.JspServlet.init() :
----------------------------------------------------------------

The parentClassLoader is set in the constructor

      // Get the parent class loader
      parentClassLoader =
          (URLClassLoader) Thread.currentThread().getContextClassLoader();
        if (parentClassLoader == null)
            parentClassLoader = (URLClassLoader)this.getClass
().getClassLoader();

but I want to dynamically change it, as I previously mentioned. The simple
solution is to have a getParentClassLoader() method that is basically the
above code, and not use the field this.parentClassLoader. I think this is
safe, but again, are there any potential bad side effects?

Thanks
-Dorian


--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message