On 7/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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

Reply via email to