cancel
Showing results for 
Search instead for 
Did you mean: 

Duplicate Message Reference

Former Member
0 Kudos

Hi Experts,

Need your views on the following issue we encountered recently.

In the message mapping stage, we are generating 25 characters unique message identifier. We are using following format to generate the unique number.

yyMMddHHmmssSSS + "SP" + 5 characters random number + "000"

yyMMddHHmmssSSS - generated using currentDate function

5 chrs random - generated using Math.Random using "User Defined" function.

Interestingly, recently for the first time we found for two messages same number got generated.

I am not very sure how could this happen.

Can you guys give me some hints?

Regards,

Ravi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Test the scenario and check the 25 characters unique message identifier again and update the thread.

post the UDF which you are using.

Regards,

Phani

Former Member
0 Kudos

Hi Phani,

Thanks for your reply.

The unique reference number logic is in production for many years, and this is the first time we encounter this issue. Here is the unique number which got duplicated.

110324164508142SP14112000

110324164508142 - currentDate formatted upto milliseconds

SP - constant

14112 - Random generated using Math Random

000 - constant.

Here is the user defined function code.


public String randomDigits(String lenStr,Container container){
int len = Integer.parseInt(lenStr);
if (len <= 0) {
  return "";
}

Random random = (Random)container.getParameter("randomDigits.random");
if (random == null) {
  random = new Random();
  container.setParameter("randomDigits.random", random);
}

StringBuffer buf = new StringBuffer(len);
for (int i=0; i<len; i++) {
  buf.append(random.nextInt(10));
}
return buf.toString();

Regards,

Ravi

Edited by: Jambunathan Ravikumar on Mar 29, 2011 12:43 PM

Former Member
0 Kudos

Use the "synchronize" block, to avoid having more than one thread accessing the same code block at the same time (mutex):

Random random = (Random)container.getParameter("randomDigits.random");
if (random == null) {
  random = new Random();
  synchronized(this) {
    container.setParameter("randomDigits.random", random);
  }
}

You can also put the synchronized function inside the "container" object.

Otherwise, you might aswell try generating a GUID for generating unique values,

http://www.javapractices.com/topic/TopicAction.do?Id=56

Edited by: Lucas Santos on Mar 29, 2011 4:09 PM

Edited by: Lucas Santos on Mar 29, 2011 4:15 PM

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Ditto... Lucas is right.

Though possibility to happen again is rare, still to avoid happening in the future use synchonized to lock the method so that while execution other threads will wait until the current thread finishes creating random number.

Also, call this line inside synchronized i.e

if(synchronized(this)){

random = new Random();

...

}

Edited by: Baskar Gopal on Mar 29, 2011 10:34 AM

Former Member
0 Kudos

Thanks a lot every one.

Answers (0)