MySQL Forums
Forum List  »  NDB clusters

Re: Exception on get method clusterj
Posted by: Craig Russell
Date: May 18, 2015 08:25PM

Hi Arco,

Yes, I (finally) got back to this issue and found the bug. The CharsetDecoder is not thread-safe, and we were using instances of the class from multiple threads as your test case shows.

http://docs.oracle.com/javase/7/docs/api/java/nio/charset/CharsetEncoder.html
"Instances of this class are not safe for use by multiple concurrent threads."

The fix is straightforward and has been pushed to our internal source tree.

If you like, you can apply this patch to the source tree and test it yourself.

If it turns out that this is a performance issue with many threads accessing decimal fields, let us know. This would mean that we would need to create a new CharsetDecoder for each Session and pass it around, which would mean a lot of extra code.

Regards,

Craig

--- a/storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/Utility.java
+++ b/storage/ndb/clusterj/clusterj-tie/src/main/java/com/mysql/clusterj/tie/Utility.java
@@ -1785,7 +1785,12 @@ public class Utility {
}
try {
// use basic decoding
- CharBuffer charBuffer = charsetDecoder.decode(digits);
+ // http://docs.oracle.com/javase/7/docs/api/java/nio/charset/CharsetEncoder.html
+ // synchronize because "Instances of this class are not safe for use by multiple concurrent threads."
+ CharBuffer charBuffer;
+ synchronized(charsetDecoder) {
+ charBuffer = charsetDecoder.decode(digits);
+ }
string = charBuffer.toString();
return string;
} catch (CharacterCodingException e) {

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Exception on get method clusterj
1017
May 18, 2015 08:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.