Adam Bien's Weblog

Endless Loops In Unsychronized WeakHashMap

Unsynchronized access to java.util.WeakHashMap may cause …an endless loop. See method java.util.WeakHashMap#get:

public V get(Object key) {
        Object k = maskNull(key);
        int h = hash(k);
        Entry[] tab = getTable();
        int index = indexFor(h, tab.length);
        Entry e = tab[index];

        while (e != null) {
            if (e.hash == h && eq(k, e.get()))
                return e.value;
            e =;

        return null;

Although it seems unlikely, it actually happens. One day we found a majority of worker threads stuck with the following stacktrace:

java.lang.Thread.State: RUNNABLE
at java.util.WeakHashMap.get(
at javax.faces.component.UIComponentBase.populateDescriptorsMapIfNecessary(
at javax.faces.component.UIComponentBase.(
at javax.faces.component.UIOutput.(

See you at Java EE Workshops at MUC Airport (March 25th-28th)!

NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices


A book about rethinking Java EE Patterns


it seems accessing ordinary (not synchronized) Maps concurrently can lead to several problems (therefore its not allowed). We observed a similar problem in a for loop in the put method using an ordinary HashMap:

java.lang.Thread.State: RUNNABLE
at java.util.HashMap.put(
at java.util.HashMap.putAll(

Posted by Jan Wiemer on October 24, 2012 at 10:26 AM CEST #

It seems that this was fixed in JDK 7:

Posted by Juraj Martinka on October 29, 2012 at 11:38 AM CET #


I agree with Jan.

It happened to me using RichFaces (3.3.3). It was a framework bug (

So interesting.


Posted by Martín Dominguez on October 29, 2012 at 05:01 PM CET #


I got a similar error in a Jasper program:

[STUCK] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)'" id=24 idx=0xb0 tid=46 prio=1 alive, native_blocked, daemon
at java/lang/ref/Reference.get([optimized]
at java/util/WeakHashMap.get(
at org/apache/commons/beanutils/MethodUtils.getMatchingAccessibleMethod(

How could I resolved this issue?

Cristo Rodríguez

Posted by Cristo Rodriguez on May 03, 2014 at 04:28 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments