Jeff Trent wrote:

> My test was not as complete are thorough as yours, but I can say that under
> Tomcat 3.2.2 running on Win2000, this is not the result I am seeing.  I'm
> finding that public variables in common.jar across multiple webapps are
> shared.
>
> Can you upload your two WAR files so that I can perform the same test
> without writing the same code / logic from scratch?
>
> thanks,
> jeff
> [...]

Hi :-)  the following is my testing code, I test it with
TC4.0-b5(standalone, J2SE1.3, winnt40):


- MyServlet:

...
public class MyServlet extends HttpServlet{
   public static String classV;  //for testing!

   public void init(ServletConfig config) throws ServletException{
      super.init(config);
   }

   public void service(HttpServletRequest req, HttpServletResponse res) throws
IOException, ServletException{
    if(req.getParameter("PclassSET")!=null){
     classV=req.getParameter("PclassSET");
     MyUtility.classU=req.getParameter("PclassSET");
    }
    if(req.getParameter("PclassGET")!=null){
           System.out.println(classV+"   "+MyUtility.classU);
           System.out.println(
"this.getClass().getClassLoader().hashCode()="+this.getClass().getClassLoader().hashCode()
);
           System.out.println(
"this.getClass().hashCode()="+this.getClass().hashCode() );
    }
...


- MyUtility:

public class MyUtility implements java.io.Serializable{
   static public String classU;
}



I have 2 "Context docBase":
  - webapps/myfolder0
  - webapps/myfolder1

I have 3 "Context path":
  - mypath0 and mypath0_bak -> webapps/myfolder0
  - mypath1 -> webapps/myfolder1

the following is testing step:
first set value to "static field":
- http://host:port/mypath0/servlet/MyServlet?PclassSET=0
- http://host:port/mypath0_bak/servlet/MyServlet?PclassSET=0_bak
- http://host:port/mypath1/servlet/MyServlet?PclassSET=1

then get value to "static field":
- http://host:port/mypath0/servlet/MyServlet?PclassGET=xxx
     result: 0   0
- http://host:port/mypath0_bak/servlet/MyServlet?PclassGET=xxx
     result: 0_bak   0_bak
- http://host:port/mypath1/servlet/MyServlet?PclassGET=xxx
     result: 1   1


Bo
June 13, 2001




>
> ----- Original Message -----
> From: "Bo Xu" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, June 13, 2001 11:10 AM
> Subject: Re: static,synchronized and classloaders
>
> > Hi :-)  I did a test with TC4.0-b5(standalone, J2SE1.3, winnt40):
> >
> > * cases:
> > -
> >    % put the Same MyServlet.class in WEB-INF/classes in
> >        Different "Context path" which has Different "Context docBase"
> >    % put the Same MyServlet.class in the Same MyJar.jar file in
> > WEB-INF/lib in
> >        Different "Context path" which has Different "Context docBase"
> >
> >    % put the Same MyUtility.class in WEB-INF/classes in
> >        Different "Context path" which has Different "Context docBase"
> >    % put the Same MyUtility.class in the Same MyJar.jar file in
> > WEB-INF/lib in
> >        Different "Context path" which has Different "Context docBase"
> >
> > -
> >    % put the Same MyServlet.class in WEB-INF/classes in
> >        Different "Context path" which has Same "Context docBase"
> >    % put the Same MyServlet.class in the Same MyJar.jar file in
> > WEB-INF/lib in
> >        Different "Context path" which has Same "Context docBase"
> >
> >    % put the Same MyUtility.class in WEB-INF/classes in
> >        Different "Context path" which has Same "Context docBase"
> >    % put the Same MyUtility.class in the Same MyJar.jar file in
> > WEB-INF/lib in
> >        Different "Context path" which has Same "Context docBase"
> >
> > * in all the above cases, all MyServlet/MyUtility of different
> >    "Context path"(NOT "Context docBase") are different in the
> >     follwing way:
> >       - classloader:     this.getClass().getClassLoader().hashCode()
> >       - Class object:   this.getClass().hashCode()
> >       (so/then), I can seprate all the "public static field" in
> > MyServlet/MyUtility by
> >       different "Context path"(NOT "Context docBase"), i.e. :
> >        % I can set "it is 0" to a "public static String field"->MyField
> > in MyServlet/MyUtility
> >           of "Context path0", and use it within "Context path0"
> >        % I can set "it is 1" to a "public static String field"->MyField
> > in MyServlet/MyUtility
> >           of "Context path1", and use it within "Context path1"
> >        - i.e.,  "Context path"/webappClassLoader/"Class object"/"static
> > field"
> >           is "independent" to the following:
> >             %  "Context docBase"
> >             %  .class file/.jar file
> >
> > and please notice that jar file in WEB-INF/lib can not be auto-reloaded,
> > so if you
> > update a jar file in WEB-INF/lib,  you need to re-start TC4.0-b5.
> >
> >
> > Bo
> > June 13, 2001
> >
> >
> >
> >
> >


Reply via email to