commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Carman <ja...@carmanconsulting.com>
Subject Re: svn commit: r1133155 - /commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/FunctionLibrary.java
Date Wed, 08 Jun 2011 15:11:31 GMT
On Wed, Jun 8, 2011 at 11:06 AM, sebb <sebbaz@gmail.com> wrote:
>
> Actually, that was not my point - fields written by one thread are not
> necessarily published to other threads without synch.
> Fields may be updated out of order or not at all.
>
> However, I've just realised that there is a real update window:
>
> 1        if (byNamespace == null) {
> 2            synchronized (this) {
> 3                //read again
> 4                if (byNamespace == null) {
> 5                    byNamespace = new HashMap();
>
> Thread A executes as far as completing line 5
> If Thread B.then executes line 1, it may see the field as non-null,
> but the map has not yet been populated.
>
> Using volatile for byNamespace would not have helped here either -
> same window can occur.
>

Why are we going into a long, drawn-out discussion about this?  We
already know how to do a keyed cache (KeyedObjectPool anyone?).  If
you don't want to introduce a dependency, just borrow some code from
Pool and be done with it.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message