diff --git a/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/SequentialID.java b/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/SequentialID.java index cf12778fe07..a577f0038c8 100644 --- a/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/SequentialID.java +++ b/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/network/SequentialID.java @@ -17,32 +17,26 @@ package org.apache.inlong.sdk.dataproxy.network; -import java.util.concurrent.atomic.AtomicLong; +import java.security.SecureRandom; +import java.util.concurrent.atomic.AtomicInteger; public class SequentialID { - private static final long maxId = 2000000000; - private String ip = null; - private AtomicLong id = new AtomicLong(0); + private static final SecureRandom sRandom = new SecureRandom( + Long.toString(System.nanoTime()).getBytes()); + private final String ip; + private final AtomicInteger id = new AtomicInteger(sRandom.nextInt()); public SequentialID(String theIp) { ip = theIp; } - public synchronized String getNextId() { - if (id.get() > maxId) { - id.set(0); - } - id.incrementAndGet(); - return ip + "#" + id.toString() + "#" + System.currentTimeMillis(); + public String getNextId() { + return ip + "#" + id.incrementAndGet() + "#" + System.currentTimeMillis(); } - public synchronized long getNextInt() { - if (id.get() > maxId) { - id.set(0); - } - id.incrementAndGet(); - return id.get(); + public int getNextInt() { + return id.incrementAndGet(); } } diff --git a/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/pb/network/TcpChannel.java b/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/pb/network/TcpChannel.java index 84f26cd2b2b..f5b79df71f5 100644 --- a/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/pb/network/TcpChannel.java +++ b/inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/pb/network/TcpChannel.java @@ -159,7 +159,7 @@ public boolean tryAcquire() { * acquireUninterruptibly */ public void acquireUninterruptibly() { - packToken.acquireUninterruptibly();; + packToken.acquireUninterruptibly(); } /**