commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael A. Smith" <...@apache.org>
Subject Re: [Collections] StaticBucketMap integration
Date Thu, 15 Aug 2002 04:23:19 GMT
Jack, Paul wrote:
> I have an idea here, though.  What if we keep the separate
> m_locks array, but instead of using vanilla Objects, use
> this class:
> 
>    private Lock[] m_locks;
> 
>    private static class Lock {
>        public int size;
>    }
> 
> Eg, each Lock instance, in addition to being the lock for 
> a bucket, also keeps count of the number of mappings in that
> bucket.  Then size() is somewhat faster:
> 
>    public int size() {
>        int r = 0;
>        for (int i = 0; i < m_buckets.length; i++) {
>            r += m_locks[i].size;
>        }
>    }
> 
> Happily, since the fetch of m_locks[i].size field IS atomic,
> we don't need any synchronized blocks!  There's still a loop
> but no monitor contention.

You could also just create an array of ints to go along side the array 
of locks...  maybe a little bit more overhead, but its one less class, 
and might be easier to look at...

michael


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message