"catalina-exec-458" #26857 daemon prio=5 os_prio=0 tid=0x00007f56a01ab800 nid=0x2517 waiting for monitor entry [0x00007f53d38f7000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.nio.charset.CoderResult$Cache.get(CoderResult.java:201)
- waiting to lock <0x00000005c0e89b58> (a java.nio.charset.CoderResult$1)
at java.nio.charset.CoderResult$Cache.access$200(CoderResult.java:194)
at java.nio.charset.CoderResult.malformedForLength(CoderResult.java:236)
at sun.nio.cs.UTF_8$Decoder.malformedN(UTF_8.java:147)
at sun.nio.cs.UTF_8$Decoder.decode(UTF_8.java:473)
at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:153)
at java.lang.StringCoding.decode(StringCoding.java:193)
at java.lang.StringCoding.decode(StringCoding.java:254)
at java.lang.String.<init>(String.java:546)
at java.lang.String.<init>(String.java:566)
The cache has a synchronized method get(int len). Can we optimize this? Replace this with a lock-free cache?
private static abstract class Cache {
private Map<Integer,WeakReference<CoderResult>> cache = null;
protected abstract CoderResult create(int len);
private synchronized CoderResult get(int len) {
if (len <= 0)
throw new IllegalArgumentException("Non-positive length");
Integer k = new Integer(len);
WeakReference<CoderResult> w;
CoderResult e = null;
if (cache == null) {
cache = new HashMap<Integer,WeakReference<CoderResult>>();
} else if ((w = cache.get(k)) != null) {
e = w.get();
}
if (e == null) {
e = create(len);
cache.put(k, new WeakReference<CoderResult>(e));
}
return e;
}
}