Charset.java (encode, decode): Synchronize on 'this', not the class.
authorTom Tromey <tromey@redhat.com>
Tue, 17 May 2005 01:52:02 +0000 (01:52 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Tue, 17 May 2005 01:52:02 +0000 (01:52 +0000)
* java/nio/charset/Charset.java (encode, decode): Synchronize on
'this', not the class.

From-SVN: r99810

libjava/ChangeLog
libjava/java/nio/charset/Charset.java

index c6295096631013e0b2cbb131fd17acc831d206c3..9c9e466603e3369bdb9004e515188911e47aab4e 100644 (file)
@@ -1,3 +1,8 @@
+2005-05-16  Tom Tromey  <tromey@redhat.com>
+
+       * java/nio/charset/Charset.java (encode, decode): Synchronize on
+       'this', not the class.
+
 2005-05-16  Tom Tromey  <tromey@redhat.com>
 
        * gnu/java/net/protocol/http/Headers.java (parse): Include final
index d52fc9c7d2198833ca5929bd9d30c8aa315e556e..8c6286db9ca26353d531b1f5aa2f66d00a8eef17 100644 (file)
@@ -289,25 +289,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)
       {
@@ -320,26 +317,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();
+       if (cachedDecoder == null)
+         {
+           cachedDecoder = newDecoder ()
+             .onMalformedInput (CodingErrorAction.REPLACE)
+             .onUnmappableCharacter (CodingErrorAction.REPLACE);
+         } else
+         cachedDecoder.reset();
 
-            return cachedDecoder.decode (bb);
-          }
+       return cachedDecoder.decode (bb);
       }
     catch (CharacterCodingException e)
       {