[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: java.util.Hashtable.size()/isEmpty()
From: |
Jeff Sturm |
Subject: |
Re: java.util.Hashtable.size()/isEmpty() |
Date: |
Fri, 15 Feb 2002 10:06:12 -0500 (EST) |
On Fri, 15 Feb 2002, Artur Biesiadowski wrote:
> If you can show me an example, where having isEmpty()/size()
> synchronized _guarantees_ anything with fully preemptive threading,
> which is not guaranteed with unsynchronized version, then let it be your
> way. But I think that no such example can be given (but I would be happy
> to be proven wrong, as this would mean I do not understand some basic
> stuff with java threading).
Your points have merit... calling isEmpty() without synchronizing isn't
very useful. But it still has side effects, like a memory barrier.
I'm wary of removing any occurrences of synchronization as an
optimization, including things like "synchronized (this) {}", because of
the implied barrier semantics. Consider:
Hashtable ht;
a = 0;
b = 0;
...
a = 1;
ht.size();
b = 1;
and in another thread:
synchronized (this) {
System.out.println(a + "," + b);
}
can this ever print 0,1?
Jeff
- Re: java.util.Hashtable.size()/isEmpty(), (continued)
- Re: java.util.Hashtable.size()/isEmpty(), Dalibor Topic, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Artur Biesiadowski, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Etienne M. Gagnon, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Artur Biesiadowski, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Etienne M. Gagnon, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Etienne M. Gagnon, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Sascha Brawer, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Jeff Sturm, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Artur Biesiadowski, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Bryce McKinlay, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(),
Jeff Sturm <=
- Re: java.util.Hashtable.size()/isEmpty(), Bryce McKinlay, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Eric Blake, 2002/02/15