[jboss-cvs] JBossCache/src/org/jboss/cache/util/concurrent ...

Manik Surtani manik at jboss.org
Wed May 23 06:28:58 EDT 2007


  User: msurtani
  Date: 07/05/23 06:28:58

  Added:       src/org/jboss/cache/util/concurrent  ConcurrentHashSet.java
  Log:
  Initiated a bunch of performance fixes, including replacing CopyOnWriteArraySets with org.jboss.cache.util.concurrent.ConcurrentHashSet.
  Also ran an imports optimiser on the code base - there were a lot of unused imports floating about.
  
  Revision  Changes    Path
  1.1      date: 2007/05/23 10:28:58;  author: msurtani;  state: Exp;JBossCache/src/org/jboss/cache/util/concurrent/ConcurrentHashSet.java
  
  Index: ConcurrentHashSet.java
  ===================================================================
  package org.jboss.cache.util.concurrent;
  
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.concurrent.ConcurrentHashMap;
  
  /**
   * A simple Set implementation backed by a {@link java.util.concurrent.ConcurrentHashMap} to deal with the fact that the
   * JDK does not have a proper concurrent Set implementation that uses efficient lock striping.
   * <p/>
   * Note that values are stored as keys in the underlying Map, with a static dummy object as value.
   *
   * @author <a href="mailto:manik at jboss.org">Manik Surtani</a>
   * @since 2.0.0
   */
  public class ConcurrentHashSet<E> implements Set<E>
  {
     protected ConcurrentHashMap<E, Object> map;
     private static final Object DUMMY = new Object();
  
     public ConcurrentHashSet()
     {
        map = new ConcurrentHashMap<E, Object>();
     }
  
     public int size()
     {
        return map.size();
     }
  
     public boolean isEmpty()
     {
        return map.isEmpty();
     }
  
     public boolean contains(Object o)
     {
        return map.containsKey(o);
     }
  
     public Iterator<E> iterator()
     {
        return map.keySet().iterator();
     }
  
     public Object[] toArray()
     {
        return map.keySet().toArray();
     }
  
     public <T> T[] toArray(T[] a)
     {
        return map.keySet().toArray(a);
     }
  
     public boolean add(E o)
     {
        Object v = map.put(o, DUMMY);
        return v == null;
     }
  
     public boolean remove(Object o)
     {
        Object v = map.remove(o);
        return v != null;
     }
  
     public boolean containsAll(Collection<?> c)
     {
        return map.keySet().containsAll(c);
     }
  
     public boolean addAll(Collection<? extends E> c)
     {
        throw new UnsupportedOperationException("Not supported in this implementation since additional locking is required and cannot directly be delegated to multiple calls to ConcurrentHashMap");
     }
  
     public boolean retainAll(Collection<?> c)
     {
        throw new UnsupportedOperationException("Not supported in this implementation since additional locking is required and cannot directly be delegated to multiple calls to ConcurrentHashMap");
     }
  
     public boolean removeAll(Collection<?> c)
     {
        throw new UnsupportedOperationException("Not supported in this implementation since additional locking is required and cannot directly be delegated to multiple calls to ConcurrentHashMap");
     }
  
     public void clear()
     {
        map.clear();
     }
  }
  
  
  



More information about the jboss-cvs-commits mailing list