abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Re: svn commit: r555837 - /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java
Date Sat, 14 Jul 2007 04:07:58 GMT
The digest(byte[]) method executes a complete sequence that ends in a
call to MessageDigest.reset(), which resets the MessageDigest for
further use.  But yeah, we should synchronize this. Good catch.

- James

Garrett Rooney wrote:
> On 7/12/07, jmsnell@apache.org <jmsnell@apache.org> wrote:
>> Author: jmsnell
>> Date: Thu Jul 12 19:22:46 2007
>> New Revision: 555837
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=555837
>> Log:
>> No need to create a new MessageDigest instance for every instance
> 
> Are you sure about this?
> 
>> +    key = getMessageDigest().digest(uri.getBytes());
> 
> The javadocs of MessageDigest.digest() say it "Performs a final update
> on the digest using the specified array of bytes, then completes the
> digest computation."  That doesn't sound like the kind of thing you
> can do multiple times, but even if it is, it doesn't sound like the
> kind of thing you can do multiple times simultaneously, and there's
> nothing here preventing multiple threads from accessing the message
> digest.
> 
>> +  }
>> +
>> +  private static MessageDigest getMessageDigest() {
>> +    if (md == null) {
>> +      try {
>> +        md = MessageDigest.getInstance("md5");
>> +      } catch (Exception e) {}
>> +    }
>> +    return md;
> 
> Similarly, this lazy initialization is not thread safe AFAICT.
> 
> -garrett
> 

Mime
View raw message