Remove unnecessary method call in PriorityBlockingQueue

David Holmes david.holmes at oracle.com
Thu May 25 05:50:29 UTC 2023


Hi Roger,

On 25/05/2023 4:57 am, Roger Riggs wrote:
> Hi,
> 
> The upstream source of PriorityBlockingQueue is the concurrency library 
> maintained by Doug Lea.
> Noting this suggestion to the Concurrency Interest mailing list is 
> recommended. [1]

Unfortunately Doug's mailing list has never returned after his mail 
server outage.

David

> Regards, Roger
> 
> [1] http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
> 
> On 5/24/23 2:51 PM, Viktor Klang wrote:
>> Sounds very reasonable.
>> ------------------------------------------------------------------------
>> *From:* core-libs-dev <core-libs-dev-retn at openjdk.org> on behalf of 
>> Aleksei Ivanov <alexey.ivanov at oracle.com>
>> *Sent:* Wednesday, 24 May 2023 20:03
>> *To:* Robin Gong <irobingong at gmail.com>; core-libs 
>> <core-libs-dev at openjdk.org>
>> *Subject:* Re: Remove unnecessary method call in PriorityBlockingQueue
>> Hi Robin,
>>
>> This belongs in core-libs.
>>
>> On 24/05/2023 16:50, Robin Gong wrote:
>>> Hi,
>>>
>>> Recently, I found this constructor in PriorityBlockingQueue:
>>>
>>>         public PriorityBlockingQueue(int initialCapacity,
>>>                                      Comparator<? super E> comparator) {
>>>             if (initialCapacity < 1)
>>>                 throw new IllegalArgumentException();
>>>             this.comparator = comparator;
>>>             this.queue = new Object[Math.max(1, initialCapacity)];
>>>         }
>>>
>>>
>>> I believe we could change 'Math.max(1, initialCapacity)' to 
>>> 'initialCapacity'. Since initialCapacity must be greater or equal to 1.
>>
>> It looks reasonable to me.
>>
>> -- 
>> Regards,
>> Alexey
>>
>>>
>>> And also that's how PriorityQueue running.
>>>
>>>         public PriorityQueue(int initialCapacity,
>>>                              Comparator<? super E> comparator) {
>>>             // Note: This restriction of at least one is not actually
>>>     needed,
>>>             // but continues for 1.5 compatibility
>>>             if (initialCapacity < 1)
>>>                 throw new IllegalArgumentException();
>>>             this.queue = new Object[initialCapacity];
>>>             this.comparator = comparator;
>>>         }
>>>
>>>
>>> Best regarts,
>>> Robin Gong
>>
> 


More information about the core-libs-dev mailing list