[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: java.util.Hashtable.size()/isEmpty()
From: |
Etienne M. Gagnon |
Subject: |
Re: java.util.Hashtable.size()/isEmpty() |
Date: |
Fri, 15 Feb 2002 08:08:34 -0500 |
User-agent: |
Mutt/1.3.27i |
On Fri, Feb 15, 2002 at 11:19:15AM +0100, Sascha Brawer wrote:
> Hello,
>
> the implementations of java.util.Hashtable.size() and
> java.util.Hashtable.isEmpty() merely access a single integer member
> field. Since accesses to integer variables are required to be atomic, I
> think these two methods don't need to be synchronized. Do people agree?
> (Yes, it's a micro-optimization).
>
I do not agree. If I remeber correctly, this atomicity is only true
of "volatile" variables. Otherwise, you have no garantee that the
integer value visible to one thread is the same as the one visible to
another on a multiprocessor system.
Be careful with such "micro-optimizations" which can be based on false
assumptions. Let the compilers/VM do these optimizations.
Etienne
--
Etienne M. Gagnon http://www.info.uqam.ca/~egagnon/
SableVM: http://www.sablevm.org/
SableCC: http://www.sablecc.org/
- java.util.Hashtable.size()/isEmpty(), Sascha Brawer, 2002/02/15
- 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 <=
- 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, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Bryce McKinlay, 2002/02/15
- Re: java.util.Hashtable.size()/isEmpty(), Eric Blake, 2002/02/15