[jboss-dev] atomic collections

Ales Justin ales.justin at gmail.com
Mon Feb 23 05:17:38 EST 2009


In MC's Deployers I found a couple of usages where I would need two+ 
steps on a Collection/Map to be atomic in this next sense:

Collection<T> addAllAndClear()
{
    Collection<T> target = new HashSet<T>();
    synchronize(delegate)
    {
       target.addAll(delegate);
       delegate.clear();
    }
    return target;
}

Does it make sense to introduce something like this in jboss-common
or should this just be handled locally in the project via some helper 
methods?

Or is AtomicCollection in order?
e.g.

public interface AtomicCollection<E> extends Collection<E>
{
    /**
     * Add all and clear.
     *
     * @return new copy
     */
    Collection<E> addAllAndClear();

    // TODO - add more 'atomic' ops here
}




More information about the jboss-development mailing list