[jboss-dev] atomic collections

Jason T. Greene jason.greene at redhat.com
Mon Feb 23 09:38:47 EST 2009


Ales Justin wrote:
> 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;
> }

That is a very badly named method. It should be something like 
"Collection<T> takeAll()" (remove everything returning a copy of what 
was removed).

> 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?
> 

I would start with something local to the project until you have 
something that is generic enough that it might be useful. With plain 
synchronized collections, most folks probably want their own locking 
designs.

-- 
Jason T. Greene
JBoss, a division of Red Hat



More information about the jboss-development mailing list