[ https://issues.apache.org/jira/browse/KAFKA-7707?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16718420#comment-16718420 ]
huangyiming commented on KAFKA-7707: ------------------------------------ Hi [~sliebau] ,thank you review, in the lock area,don't have another thread add Condition to the waiters. the waiters only have one condition {code:java} public ByteBuffer allocate(int size, long maxTimeToBlockMs) throws InterruptedException { if (size > this.totalMemory) throw new IllegalArgumentException("Attempt to allocate " + size + " bytes, but there is a hard limit of " + this.totalMemory + " on memory allocations."); ByteBuffer buffer = null; this.lock.lock(); try { // check if we have a free buffer of the right size pooled if (size == poolableSize && !this.free.isEmpty()) return this.free.pollFirst(); // now check if the request is immediately satisfiable with the // memory on hand or if we need to block int freeListSize = freeSize() * this.poolableSize; if (this.nonPooledAvailableMemory + freeListSize >= size) { // we have enough unallocated or pooled memory to immediately // satisfy the request, but need to allocate the buffer freeUp(size); this.nonPooledAvailableMemory -= size; } else { // we are out of memory and will have to block int accumulated = 0; Condition moreMemory = this.lock.newCondition(); try { long remainingTimeToBlockNs = TimeUnit.MILLISECONDS.toNanos(maxTimeToBlockMs); this.waiters.addLast(moreMemory); {code} and finally we have remove the Condition: {code:java} } finally { // When this loop was not able to successfully terminate don't loose available memory this.nonPooledAvailableMemory += accumulated; this.waiters.remove(moreMemory); } {code} so i think in the last finally: {code:java} } finally { // signal any additional waiters if there is more memory left // over for them try { if (!(this.nonPooledAvailableMemory == 0 && this.free.isEmpty()) && !this.waiters.isEmpty()) this.waiters.peekFirst().signal(); } finally { // Another finally... otherwise find bugs complains lock.unlock(); } } {code} can modify like this: {code:java} } finally { lock.unlock(); } {code} > Some code is not necessary > -------------------------- > > Key: KAFKA-7707 > URL: https://issues.apache.org/jira/browse/KAFKA-7707 > Project: Kafka > Issue Type: Improvement > Reporter: huangyiming > Priority: Minor > Attachments: image-2018-12-05-18-01-46-886.png > > > In the trunk branch in > [BufferPool.java|https://github.com/apache/kafka/blob/578205cadd0bf64d671c6c162229c4975081a9d6/clients/src/main/java/org/apache/kafka/clients/producer/internals/BufferPool.java#L174], > i think the code can clean,is not necessary,it will never execute > {code:java} > if (!(this.nonPooledAvailableMemory == 0 && this.free.isEmpty()) && > !this.waiters.isEmpty()) > this.waiters.peekFirst().signal(); > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)