From e883d720de063864643b395b9ce48c2661821296 Mon Sep 17 00:00:00 2001 From: John DeRegnaucourt Date: Wed, 10 Jan 2024 01:43:42 -0500 Subject: [PATCH] Updated comments. --- .../cedarsoftware/util/UniqueIdGenerator.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java b/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java index fa06418f..aa69be4c 100644 --- a/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java +++ b/src/main/java/com/cedarsoftware/util/UniqueIdGenerator.java @@ -127,13 +127,15 @@ private static int getServerId(String externalVarName) * number. This number is chosen when the JVM is started and then stays fixed until next restart. This is to * ensure cluster uniqueness.
*
- * There is the possibility two machines could choose the same random number at start. Even still, collisions would - * be highly unlikely because for a collision to occur, a number would have to be chosen at the same millisecond - * with the count at the same position.
+ * Because there is the possibility two machines could choose the same random number and be at the same cound, at the + * same time, a unique machine index is chosen to provide a 00 to 99 value for machine instance within a cluster. + * To set the unique machine index value, set the environment variable JAVA_UTIL_CLUSTERID to a unique two-digit + * number on each machine in the cluster. If the machines are managed by CloundFoundry, the uniqueId will use the + * CF_INSTANCE_INDEX to provide unique machine ID. Only if neither of these environment variables are set, will it + * resort to using a random number from 00 to 99 for the machine instance number portion of the unique ID.
*
* This API is slower than the 19 digit API. Grabbing a bunch of IDs in a tight loop for example, could cause - * delays while it waits for the millisecond to tick over. This API can return 1,000 unique IDs per millisecond - * max.
+ * delays while it waits for the millisecond to tick over. This API can return up to 1,000 unique IDs per millisecond.
*
* The IDs returned are guaranteed to be strictly increasing. * @@ -178,14 +180,17 @@ private static long getUniqueIdAttempt() * This is followed by a random 2 digit number. This number is chosen when the JVM is started and then stays fixed * until next restart. This is to ensure cluster uniqueness.
*
- * There is the possibility two machines could choose the same random number at start. Even still, collisions would - * be highly unlikely because for a collision to occur, a number would have to be chosen at the same millisecond - * with the count at the same position.
+ * Because there is the possibility two machines could choose the same random number and be at the same cound, at the + * same time, a unique machine index is chosen to provide a 00 to 99 value for machine instance within a cluster. + * To set the unique machine index value, set the environment variable JAVA_UTIL_CLUSTERID to a unique two-digit + * number on each machine in the cluster. If the machines are managed by CloundFoundry, the uniqueId will use the + * CF_INSTANCE_INDEX to provide unique machine ID. Only if neither of these environment variables are set, will it + * resort to using a random number from 00 to 99 for the machine instance number portion of the unique ID.
*
* The returned ID will be 19 digits and this API will work through 2286. After then, it would likely return * negative numbers (still unique).
*
- * This API is faster than the 18 digit API. This API can return 10,000 unique IDs per millisecond max.
+ * This API is faster than the 18 digit API. This API can return up to 10,000 unique IDs per millisecond.
*
* The IDs returned are guaranteed to be strictly increasing. *