• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronized method to get md5 digest

 
TC
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some problem in getting digest value.
printDigest() below is called in my servlet (doGet).
it works perfectly by printing correct digest value.
but there is some broblem when I fired 30 requests using Jmeter to access doGet concurrently.
some results I got is not correct value.
but when I did synchronized printDigest method it returns correct result.
I wonder that why I need to synchronize it bcoz there is no shared variable in this class.

private void printDigest() {
byte[] psw = null;
try {
byte[] digest = md5.digest("x".getBytes("UTF-8"));
printHex(digest);
} catch (UnsupportedEncodingException ex) {
}

}

Does anyone have an idea?

Thanks
TC
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

It looks to me like "md5" is a shared variable -- it's a member variable of the servlet, shared by all request threads.
 
TC
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it.
I thought MessageDigest itself is sigleton (MessageDigest.getInstance())
so I made md5 as shared variable.

Thank you so much.
TC
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!

By the way, I didn't notice earlier, but your display name doesn't satisfy our naming policy -- you need to use a real full first and last name. You can fix it here; please do so as soon as you can. Thanks, pardner!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!