You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by Justin Ling Mao <ma...@sina.com> on 2019/07/05 08:26:34 UTC

Re: Zookeeper code optimization

A good code optimizationCould you plz help us improve this issue?The contributor guideline is [here](https://cwiki.apache.org/confluence/display/ZOOKEEPER/HowToContribute])

----- Original Message -----
From: 18779116352 <18...@163.com>
To: dev <de...@zookeeper.apache.org>
Subject: Zookeeper code optimization
Date: 2019-06-25 01:21

Dear developer:
    I think the following code in line 623 of the QuorumCnxManager class can be optimized:
    ArrayBlockingQueue<ByteBuffer> bq = new ArrayBlockingQueue<ByteBuffer>(
SEND_CAPACITY);
ArrayBlockingQueue<ByteBuffer> oldq = queueSendMap.putIfAbsent(sid, bq);
if (oldq != null) {
addToSendQueue(oldq, b);
} else {
addToSendQueue(bq, b);
}
    The optimization is as follows:
        ArrayBlockingQueue<ByteBuffer> bq = queueSendMap.computeIfAbsent(sid, serverId -> new ArrayBlockingQueue<>(SEND_CAPACITY));
addToSendQueue(bq, b);
Thanks
    
| |
18779116352
邮箱:18779116352@163.com
|
Signature is customized by Netease Mail Master