On Wed, Jun 8, 2011 at 11:06 AM, sebb <seb...@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-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to