tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cox, Charlie" <>
Subject RE: static,synchronized and classloaders(was:Java Question)
Date Tue, 12 Jun 2001 19:35:39 GMT
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. 


-----Original Message-----
From: Pae Choi []
Sent: Tuesday, June 12, 2001 2:42 PM
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


> 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
> 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
> return the right results?  If not, do I have to synchronize it or
> 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

View raw message