Timestamp in GlobalIdGenerator is implemented using ThreadLocalRandom (#6623)
This commit is contained in:
parent
92c0cb856d
commit
f3ca0d0ea5
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
package org.apache.skywalking.apm.agent.core.context.ids;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.skywalking.apm.util.StringUtil;
|
||||
|
||||
public final class GlobalIdGenerator {
|
||||
|
|
@ -58,7 +59,6 @@ public final class GlobalIdGenerator {
|
|||
// Just for considering time-shift-back only.
|
||||
private long runRandomTimestamp;
|
||||
private int lastRandomValue;
|
||||
private Random random;
|
||||
|
||||
private IDContext(long lastTimestamp, short threadSeq) {
|
||||
this.lastTimestamp = lastTimestamp;
|
||||
|
|
@ -74,11 +74,8 @@ public final class GlobalIdGenerator {
|
|||
|
||||
if (currentTimeMillis < lastTimestamp) {
|
||||
// Just for considering time-shift-back by Ops or OS. @hanahmily 's suggestion.
|
||||
if (random == null) {
|
||||
random = new Random();
|
||||
}
|
||||
if (runRandomTimestamp != currentTimeMillis) {
|
||||
lastRandomValue = random.nextInt();
|
||||
lastRandomValue = ThreadLocalRandom.current().nextInt();
|
||||
runRandomTimestamp = currentTimeMillis;
|
||||
}
|
||||
return lastRandomValue;
|
||||
|
|
|
|||
Loading…
Reference in New Issue