Title: RE: static,synchronized and classloaders
Are you saying that I don't need different JVMs to handle each of my webapps if I move the JAR files that I have in my classpath down into the lib directory of the webapp?  I have a problem in that this JAR I'm using in several of my webapp contexts uses static class members to carry configuration information that gets corrupted by the very next webapp that initializes the same shared library with different configuration information.
 
thanks,
jeff
 
----- Original Message -----
Sent: Wednesday, June 13, 2001 8:40 AM
Subject: RE: static,synchronized and classloaders

I'm not sure what you mean by abc.MyClass and xyz.MyClass as the class in question is in the same package in both contexts.

This archive link from Craig McClanahan(thank you Craig) gives a good explaination of classloaders:
http://www.mail-archive.com/[email protected]/msg13260.html
 
Based upon this, the individual web app classloader does not know about the other webapp classloaders or the classes that they have loaded. That's why I think MyObject is treated as two classes since it is loaded by two different loaders at the same level in the class-loader heirarchy. I am currently using the same servlet class under two class loaders. It is not throwing any errors. The difference in my contexts is in my properties file that is context-specific and loaded by the servlet.

Actually now that I think about it, I do have a static field that is remaining context-specific in my servlet, therefore it must be two different Class objects representing my class; therefore two different instances of my static members(confusing isn't it?).

I guess I answered my own question. ;) And since I already typed this email, I'll send it anyway and hopefully someone else will find it useful.

you can synchonize on the class by using the 'this' object(I am doing it). I'm just not sure if 'this' is available for static classes.I would think that it is.

Charlie

-----Original Message-----
From: Luba Powell [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 12, 2001 3:50 PM
To: [EMAIL PROTECTED]
Subject: Re: static,synchronized and classloaders(was:Java Question)


Also, look if identical files are generated based on 2 different context:
abc.MyClass is not the same as xyx.MyClass.  If 2 class loaders
load from identical class files - JVM verifier should throw the exception
before a second object is created. If this doesn't happen - this is a
serious bug.
 
Also it is not possible to synchronize on the class - only on the method
and a variable that is an object
----- Original Message -----
From: Cox, Charlie
To: '[EMAIL PROTECTED]'
Sent: Tuesday, June 12, 2001 3:35 PM
Subject: RE: static,synchronized and classloaders(was:Java Question)


Now is this true for when I have multiple contexts mapped to the same docbase?  I have seen on this list that Tomcat loads the classes(in web-inf/classes) independently for each context and passing MyObject class instance between contexts is not the same 'MyObject' class in the second context even though it is the same code. Since it is not the same class I would assume that I would have two instances of a static method/field. And if it is synchronized on a static member(or the class itself) it would only be synchonized for this context.

I'm really not sure what I would have if the class is static.
Thoughts?
Charlie
-----Original Message-----
From: Pae Choi [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 12, 2001 2:42 PM
To: [EMAIL PROTECTED]
Subject: Re: Java Question


When you access the 'synchronized' static method, it locks its class.
so this will ensure the thread-safe access. Otherwise, the result is
unknown.


Pae


> I have looked all over and can't find the answer to this simple question.
> If you use a static method, do you have to synchronize it in case other
> people may access it at the same time.  For example, I have a static Utility
> class to do date calculations.  The method Utility.getMonth(String date)
> takes in a full date string, parses it, and returns just the month value.
> If 5 different people all using the website attempt to use
> Utility.getMonth(String date) at the same time for different dates, will it
> return the right results?  If not, do I have to synchronize it or something
> in case multiple users attempt to access it?
>
> I know this is not really related to tomcat, but since I am using tomcat,
> and everyone else using tomcat is also a java developer, I figured this is
> the best place I can ask.
>
> Thanks for any help!!!
>
> Brandon
>

Reply via email to