classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: java.util.Properties -- make it thread-safe?


From: Mark Wielaard
Subject: Re: java.util.Properties -- make it thread-safe?
Date: 15 Feb 2002 14:31:04 +0100

Hi,

On Fri, 2002-02-15 at 12:53, Sascha Brawer wrote:
>
> Sun's current JavaDoc (J2SE 1.4) does not mention whether
> java.util.Properties is supposed to be usable from multiple threads
> without additional synchronization.  However, one might be able to infer
> it from the fact that it is a subclass of java.util.Hashtable.
> 
> Sun's JavaDoc (JDK1.1) specified only load and save as synchronized.

When you want to be compatible with the API spec then having the same
synchronization is important. A programmer can synchronize on any
object, when a method does declare that it is synchronized the
programmer knows that the calling thread will have to get the lock for
that object (or class when static). So changing the synchronization of a
method can lead to subtle deadlock problems.

> (Newer javadoc versions do not emit "synchronized" anymore).
>
> Actually, I am curious what people do in general for determining what the
> Sun reference implementation does about synchronization. 
> Nondeterministic behavior is not easy to observe, after all.  And I think
> running javap to see which methods are synchronized is out of the
> question, since this would count as decompilation.

Being thread-save and synchronizing are not completely the same thing.
Wether a object/method is thread-save should be in the specification.
Having some methods synchronized is a big hint that an object is thread
save (if all methods that change state on the object are synchronized,
thread-safety comes automatically).

Do newer versions of javadoc really no longer mention wether a method is
synchronized? That would be not good.

> Or should one file bug reports with Sun, saying that the spec is not clear?

Yes, filing a bug report is a good idea if the spec is unclear on this
point.

Cheers,

Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]