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
}