summaryrefslogtreecommitdiff
path: root/java/nio
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2005-05-17 01:52:25 +0000
committerTom Tromey <tromey@redhat.com>2005-05-17 01:52:25 +0000
commit39519d6d11f4d0b74c2eed46c7446d60f6540713 (patch)
tree9ad55b422476312b1df0ce3a43a60c8dea386244 /java/nio
parent739f9800cf3bdc03a795cd21dfbfa7b98dc774d7 (diff)
downloadclasspath-39519d6d11f4d0b74c2eed46c7446d60f6540713.tar.gz
* java/nio/charset/Charset.java (encode, decode): Synchronize on
'this', not the class.
Diffstat (limited to 'java/nio')
-rw-r--r--java/nio/charset/Charset.java60
1 files changed, 27 insertions, 33 deletions
diff --git a/java/nio/charset/Charset.java b/java/nio/charset/Charset.java
index 349f0f86e..dd28bd93b 100644
--- a/java/nio/charset/Charset.java
+++ b/java/nio/charset/Charset.java
@@ -329,25 +329,22 @@ public abstract class Charset implements Comparable
return true;
}
- public final ByteBuffer encode (CharBuffer cb)
+ // NB: This implementation serializes different threads calling
+ // Charset.encode(), a potential performance problem. It might
+ // be better to remove the cache, or use ThreadLocal to cache on
+ // a per-thread basis.
+ public final synchronized ByteBuffer encode (CharBuffer cb)
{
try
{
- // NB: This implementation serializes different threads calling
- // Charset.encode(), a potential performance problem. It might
- // be better to remove the cache, or use ThreadLocal to cache on
- // a per-thread basis.
- synchronized (Charset.class)
- {
- if (cachedEncoder == null)
- {
- cachedEncoder = newEncoder ()
- .onMalformedInput (CodingErrorAction.REPLACE)
- .onUnmappableCharacter (CodingErrorAction.REPLACE);
- } else
- cachedEncoder.reset();
- return cachedEncoder.encode (cb);
- }
+ if (cachedEncoder == null)
+ {
+ cachedEncoder = newEncoder ()
+ .onMalformedInput (CodingErrorAction.REPLACE)
+ .onUnmappableCharacter (CodingErrorAction.REPLACE);
+ } else
+ cachedEncoder.reset();
+ return cachedEncoder.encode (cb);
}
catch (CharacterCodingException e)
{
@@ -360,26 +357,23 @@ public abstract class Charset implements Comparable
return encode (CharBuffer.wrap (str));
}
- public final CharBuffer decode (ByteBuffer bb)
+ // NB: This implementation serializes different threads calling
+ // Charset.decode(), a potential performance problem. It might
+ // be better to remove the cache, or use ThreadLocal to cache on
+ // a per-thread basis.
+ public final synchronized CharBuffer decode (ByteBuffer bb)
{
try
{
- // NB: This implementation serializes different threads calling
- // Charset.decode(), a potential performance problem. It might
- // be better to remove the cache, or use ThreadLocal to cache on
- // a per-thread basis.
- synchronized (Charset.class)
- {
- if (cachedDecoder == null)
- {
- cachedDecoder = newDecoder ()
- .onMalformedInput (CodingErrorAction.REPLACE)
- .onUnmappableCharacter (CodingErrorAction.REPLACE);
- } else
- cachedDecoder.reset();
-
- return cachedDecoder.decode (bb);
- }
+ if (cachedDecoder == null)
+ {
+ cachedDecoder = newDecoder ()
+ .onMalformedInput (CodingErrorAction.REPLACE)
+ .onUnmappableCharacter (CodingErrorAction.REPLACE);
+ } else
+ cachedDecoder.reset();
+
+ return cachedDecoder.decode (bb);
}
catch (CharacterCodingException e)
{