diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java index c243258a247..51ec2f2ec88 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/Request.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.utils.StringUtils; +import java.security.SecureRandom; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.atomic.AtomicLong; @@ -28,7 +29,7 @@ */ public class Request { - private static final AtomicLong INVOKE_ID = new AtomicLong(ThreadLocalRandom.current().nextLong()); + private static final AtomicLong INVOKE_ID; private final long mId; @@ -50,6 +51,16 @@ public Request(long id) { mId = id; } + static { + long startID = ThreadLocalRandom.current().nextLong(); + try { + SecureRandom rand = new SecureRandom(SecureRandom.getSeed(20)); + startID = rand.nextLong(); + } catch (Throwable ignore) { + } + INVOKE_ID = new AtomicLong(startID); + } + private static long newId() { // getAndIncrement() When it grows to MAX_VALUE, it will grow to MIN_VALUE, and the negative can be used as ID return INVOKE_ID.getAndIncrement();