未验证 提交 f3ca0d0e 编写于 作者: K Kirs 提交者: GitHub

Timestamp in GlobalIdGenerator is implemented using ThreadLocalRandom (#6623)

上级 92c0cb85
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册