
Signature
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
>> If you have a class with more than one synchronized static method, are
>> the methods synchronized from each other? What object are they
[quoted text clipped - 10 lines]
> }
> }
Someone pointed out to me once that there's nothing in the Java docs that
says explicitly "All calls to ClassName.class" will result in the same
object" [1], but the fact that static synchronization works the way it does
implies this.
1. It isn't, as far as I know, guaranteed that all calls to
Class.getMethod(), for instance, result in the same Method object.
Thomas Hawtin - 06 Mar 2006 10:59 GMT
> 1. It isn't, as far as I know, guaranteed that all calls to
> Class.getMethod(), for instance, result in the same Method object.
I should hope not. java.lang.reflect.Method objects are mutable.
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Lee Fesperman - 07 Mar 2006 01:23 GMT
> >> If you have a class with more than one synchronized static method, are
> >> the methods synchronized from each other? What object are they
[quoted text clipped - 15 lines]
> object" [1], but the fact that static synchronization works the way it does
> implies this.
Yep, it seems that the Class object for a given class should be 'unique'. The javadocs
I'm looking at sorta imply that this is true by explicitly saying that Class objects for
each type of array are unique -- "Every array also belongs to a class that is reflected
as a Class object that is *shared* by all arrays with the same element type and number
of dimensions." (emphasis mine). The javadocs for Class.forName() also say "Returns the
Class object associated with the class or interface with the given string name.", rather
than saying "Returns a Class object".
I also think it should be unique within a given classloader but not between
classloaders, lest unexpected (and unfortunate) conflicts arise.
Synchronization of static methods provide another distinction from instance methods.
Synchronized instance methods in super/sub classes all synchronize on the same monitor
within an instance. A synchronized static method synchronizes on a different monitor
than a synchronized static method in its superclass.
> 1. It isn't, as far as I know, guaranteed that all calls to
> Class.getMethod(), for instance, result in the same Method object.
As Thomas mentioned, Method objects are mutable ... because of setAccessible().

Signature
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
Knute Johnson - 07 Mar 2006 02:12 GMT
Thanks very much, everybody, for your answers to my post.

Signature
Knute Johnson
email s/nospam/knute/