From: <mar...@us...> - 2010-09-28 10:42:07
|
Revision: 3650 http://bigdata.svn.sourceforge.net/bigdata/?rev=3650&view=rev Author: martyncutcher Date: 2010-09-28 10:42:00 +0000 (Tue, 28 Sep 2010) Log Message: ----------- change addFilter to use LinkedList and lock for concurrency Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java Modified: branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java =================================================================== --- branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java 2010-09-28 10:08:25 UTC (rev 3649) +++ branches/QUADS_QUERY_BRANCH/ctc-striterators/src/java/cutthecrap/utils/striterators/Striterator.java 2010-09-28 10:42:00 UTC (rev 3650) @@ -27,8 +27,10 @@ import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; /** @@ -40,7 +42,7 @@ * The <code>addTypeFilter</code> method allows easy specification of a class type restriction. */ public class Striterator implements IStriterator { - private List<IFilter> filters = null; // Note: NOT serializable. + volatile List<IFilter> filters = null; // Note: NOT serializable. private transient Iterator realSource; private transient Iterator m_src = null; @@ -101,9 +103,20 @@ /** creates a Filterator to apply the filter **/ public IStriterator addFilter(final IFilter filter) { - if (filters == null) - filters = new ArrayList<IFilter>(); - + if (filters == null) { + synchronized (this) { + /* + * Note: double-checked locking pattern and volatile field are + * used to ensure visibility in combination with lazy create of + * the backing list. + */ + if (filters == null) { + filters = Collections + .synchronizedList(new LinkedList<IFilter>()); + } + } + } + filters.add(filter); return this; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |