I haven't looked recently at how much threading related code Avalon has 
in it, but I would really suggest staying away from reinventing the 
wheel. As opposed to a lot of other types of code, writing good, 
efficient, safe threading code is relatively hard to do on the scale of 
things. Why not use something like Doug Lea's util.concurrent package?
  
http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
The stuff is fantastic. It's been around for years, does a ton of stuff, 
is well tested and efficient, and is completely free. He even has a book 
that gets into most of the concept of what the code does.


Berin Loritsch wrote:

> I remember reading an article on how to implement an efficient 
> ThreadSafe hashmap.
> The problem is that I can't remember where.  The concept is to reduce 
> the locking
> contention to a "bucket".  The implementation they had was fairly 
> simple, and
> went something along these lines:
>
> LockedBucketMap
> {
>     Object[] locks;
>     Node[] buckets;
>
>     LockedBucketMap()
>     {
>         this(256);
>     }
>
>     LockedBucketMap( int numBockets )
>     {
>         locks = new Object[numBuckets];
>         buckets = new Node[numBuckets];
>
>         for (int i = 0; i < locks.length; i++)
>         {
>             locks[i] = new Object();
>         }
>     }
>
>     void put( Object key, Object value )
>     {
>         int hash = getHash(key);
>
>         Node node = null;
>
>         synchronized( locks[hash] )
>         {
>             node = buckets[hash];
>             if (node == null)
>             {
>                 buckets[hash] = new Node( key, value );
>             }
>             else
>             {
>                 while (node != null)
>                 {
>                     node = node.next;
>                 }
>                 node.next = new Node(key, value);
>             }
>         }
>     }
>
>     Object get( Object key )
>     {
>         int hash = getHash(key);
>         Node node = null;
>         Object value = null;
>
>         synchronized( locks[hash] )
>         {
>             node = buckets[hash];
>
>             while (node != null)
>             {
>                 if (node.key.equals(key)) return node.value;
>                 node = node.next;
>             }
>         }
>         return value;
>     }
>
>     int getHash( Object key )
>     {
>         return key.hashCode() % buckets.length;
>     }
>
>     class Node
>     {
>         Object key;
>         Object value;
>         Node next;
>     }
> }
>
> I don't have time to test it, debug it, or optimize it (what about using
> ArrayList and a Node that matches against the key object etc. for 
> lookup).
> Could someone take the ball and run with it?  We desperately need to 
> reduce
> thread contention on the ECM and ContainerManager implementations.
>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to