abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Garrett Rooney" <roo...@electricjellyfish.net>
Subject Re: svn commit: r555837 - /incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/SimpleCacheKey.java
Date Fri, 13 Jul 2007 14:03:14 GMT
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