harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Ellison (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-665) [classlib][nio]Charset.encode()/decode() should be more safer for multi thread using
Date Tue, 27 Jun 2006 15:19:30 GMT
    [ http://issues.apache.org/jira/browse/HARMONY-665?page=comments#action_12418042 ] 

Tim Ellison commented on HARMONY-665:
-------------------------------------

Paulex, looking at the patch I think you have too far the other way now ;-)

If you remove all synchronization then the cachedCharset[En|De]coderTable HashMap may become
inconsistent in the face of multiple put()'s, or one or more get()'s and put's().

The code today has a synchronized block that includes creating a new [En|De]coder, when really
it need only protect the table itself.  If you think other threads should wait and get the
cached result, then let's leave the code as it is now; otherwise we should remove the synchronization
block and make the HashMap a synchronizedMap.


> [classlib][nio]Charset.encode()/decode() should be more safer for multi thread using
> ------------------------------------------------------------------------------------
>
>          Key: HARMONY-665
>          URL: http://issues.apache.org/jira/browse/HARMONY-665
>      Project: Harmony
>         Type: Bug

>   Components: Classlib
>     Reporter: Paulex Yang
>     Assignee: Tim Ellison
>  Attachments: Harmony-665-2.diff, Harmony-665.diff
>
> As discussion on the mailing list, current Harmony codes may throw exception for the
scenario below:
>          for (int i = 0; i < THREAD_NUM; i++) {
>               thread[i] = new Thread() {
>                   public void run() {
>                      sink.write(ByteBuffer.wrap("bytes"
>                                         .getBytes(ISO8859_1)));
>                     }
>         }
> String.getBytes() actually invokes Charset.encode(), while spec requires Charset.encode()
to be thread-safe. Current Harmony implementation of Charset.encode() holds lock on this Charset
instance, but doesn't synchronize on the system wide cached CharsetEncoder, so it is not safe
for multi Charset instances in multi threads to encode() concurrently. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message