Originally posted by Mr. C Lamont Gilbert:
You cant synchronize on an int anyway so that won't compile.
I changed int to Integer. I figured anyone reading would assume that, sorry for the confusion. Would there be anything wrong with using an Integer?
Originally posted by Mr. C Lamont Gilbert:
It was better before. A synchronized method only stops entry into other synchronized methods that use the same monitor; it does not effect entry into unsynchronized methods. It also does not stop entry into other synchronized methods that synchronize on a different monitor.
I disagree with your statement that it's better. I don't dispute anything else in that paragraph, but I also don't see the
point. It doesn't stop unsychronized methods, but the only unsynchronized method of relevence
calls a synchronized method to do the work.
Does a synchronized static method
not lock the monitor on the entire Class? As far as I'm aware, a synchronized static method will block
all synchronized methods of the same Class including both static and normal instance methods. That means if a
thread called getUID() or getUIDAsString() no other methods could be called (or at least not return) until it was finished. Yes, getUID() and getNextUID() could be
called but they couldn't ever return until the lock was given up since they depend on the synchronized methods getUIDAsString() and getNextAsString().
Originally posted by Mr. C Lamont Gilbert:
This introduces a new concept to me of using the monitor of an Object we don't really care about to restrict access to critical sections. That being said, it seems silly in this case. I can just use TIMEMS instead. Why not? You only lose lazy instantiation which is no gain to begin with since you're having to create the other Object. Wouldn't this be optimal:
You made me realize I don't need a lock on ORDINAL because all the code that accesses ORDINAL and TIMEMS will logically need a lock on TIMEMS. I just have to be sure that in the future developers know to never make those accessible to the public and to always lock on TIMEMS if they add in methods that modify ORDINAL or TIMEMS. Am I wrong?
[ October 14, 2005: Message edited by: Ken Blair ]