Make NettyTransportClient.getCurrentId() thread safe (#1707)
Fix issue #1705. - Use CAS to make it thread safe and limited in the declared range. Signed-off-by: cj <power4j@outlook.com>
This commit is contained in:
parent
b7b54034cc
commit
34fc435ce5
|
|
@ -238,10 +238,12 @@ public class NettyTransportClient implements ClusterTransportClient {
|
|||
}
|
||||
|
||||
private int getCurrentId() {
|
||||
if (idGenerator.get() > MAX_ID) {
|
||||
idGenerator.set(0);
|
||||
}
|
||||
return idGenerator.incrementAndGet();
|
||||
int pre, next;
|
||||
do {
|
||||
pre = idGenerator.get();
|
||||
next = pre >= MAX_ID ? MIN_ID : pre + 1;
|
||||
} while (!idGenerator.compareAndSet(pre, next));
|
||||
return next;
|
||||
}
|
||||
|
||||
/*public CompletableFuture<ClusterResponse> sendRequestAsync(ClusterRequest request) {
|
||||
|
|
@ -266,5 +268,6 @@ public class NettyTransportClient implements ClusterTransportClient {
|
|||
return future;
|
||||
}*/
|
||||
|
||||
private static final int MIN_ID = 1;
|
||||
private static final int MAX_ID = 999_999_999;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue