You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/03/26 00:34:09 UTC
[skywalking] branch master updated: Timestamp in GlobalIdGenerator
is implemented using ThreadLocalRandom (#6623)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new f3ca0d0 Timestamp in GlobalIdGenerator is implemented using ThreadLocalRandom (#6623)
f3ca0d0 is described below
commit f3ca0d0ea52bf05df87e9b1e268b7f5d69423a88
Author: Kirs <ac...@163.com>
AuthorDate: Fri Mar 26 08:33:36 2021 +0800
Timestamp in GlobalIdGenerator is implemented using ThreadLocalRandom (#6623)
---
.../skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java
index 21a85b0..0adb77d 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ids/GlobalIdGenerator.java
@@ -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;