fix possible duplicate keys

This commit is contained in:
Sebastian Sdorra
2012-09-02 17:14:56 +02:00
parent d7c7814f04
commit a94a2bf774
2 changed files with 36 additions and 1 deletions

View File

@@ -51,6 +51,12 @@ import java.util.concurrent.atomic.AtomicLong;
public class DefaultKeyGenerator implements KeyGenerator
{
/** Field description */
private static final int RANDOM_MAX = 999;
/** Field description */
private static final int RANDOM_MIN = 100;
/**
* the logger for DefaultKeyGenerator
*/
@@ -72,7 +78,7 @@ public class DefaultKeyGenerator implements KeyGenerator
buffer.append(Long.toHexString(System.currentTimeMillis()));
buffer.append(Long.toHexString(sessionKey.incrementAndGet()));
buffer.append(Integer.toHexString(random.nextInt(999)));
buffer.append(Integer.toHexString(createRandom()));
String key = buffer.toString();
@@ -84,6 +90,17 @@ public class DefaultKeyGenerator implements KeyGenerator
return key;
}
/**
* Create a random int between {@link #RANDOM_MIN} and {@link #RANDOM_MAX}.
* This method is package visible for testing.
*
* @return a random int between the min and max value
*/
int createRandom()
{
return random.nextInt(RANDOM_MAX - RANDOM_MIN + 1) + RANDOM_MIN;
}
//~--- fields ---------------------------------------------------------------
/** Field description */