public ClientConnectionsEntry getEntry(List<ClientConnectionsEntry> clientsCopy){
//java.util.concurrent.ThreadLocalRandom; int ind = ThreadLocalRandom.current().nextInt(clientsCopy.size());return clientsCopy.get(ind);}
RoundRobinLoadBalancer -轮询调度算法
privatefinal AtomicInteger index =newAtomicInteger(-1);//cas,保证变量在多线程下的准确性public ClientConnectionsEntry getEntry(List<ClientConnectionsEntry> clientsCopy){
int ind = Math.abs(index.incrementAndGet()% clientsCopy.size());return clientsCopy.get(ind);}
WeightedRoundRobinBalancer - 权重轮询调度算法
RedissonLock中主要方法的源码分析
lock 方法
privatevoidlock(long leaseTime, TimeUnit unit,boolean interruptibly)throws InterruptedException {
long threadId = Thread.currentThread().getId();//尝试获取锁
Long ttl =tryAcquire(leaseTime, unit, threadId);// lock acquired 获取锁成功if(ttl == null){
return;}// 通过异步方式订阅Redis的channel,阻塞方式获取订阅结果
RFuture<RedissonLockEntry> future =subscribe(threadId);
commandExecutor.syncSubscription(future);try{
while(true){