This content has been marked as final. Show 2 replies
I would guess that you're using some of the static methods in the CoderResult class. The static methods CoderResult.unmappableCache(), CoderResult.malformedForLength() and CoderResult.malformedCache all use a static inner class called Cache. Its get() method is synchronized on Cache.class. Since the Cache inner-class is static, any part of your multi-threaded application that goes through the Cache.get() method is going to be waiting for the lock on Cache.class.
Could you create a CoderResult instance for each thread? That would mean that there would be a different static Cache class for each thread, reducing the number of threads competing for the Cache.class lock.
I'd have to see some of your code to give a better answer.
I am seeing the exact same behaviour in an application doing lots of conversion from byte arrays to UTF-8 strings. And I can confirm that it is in Cache.get that the blocking occurs.
The code I am using is this (assume that the charset is defined somewhere else):
What do you mean by "Could you create a CoderResult instance for each thread?"?
final CharBuffer buffer = charset.decode(ByteBuffer.wrap(out.toByteArray())); return buffer.toString();