[jboss-jira] [JBoss JIRA] (JGRP-2445) MessageBatch: removal on iteration is inefficient

Bela Ban (Jira) issues at jboss.org
Tue Feb 4 08:28:36 EST 2020


    [ https://issues.redhat.com/browse/JGRP-2445?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13963057#comment-13963057 ] 

Bela Ban commented on JGRP-2445:
--------------------------------

The above code occurrences have been replaced with
{code:java}
MessageIterator it=batch.iterator();
while(it.hasNext()) {
   Message msg=it.next();
   if(condition)
       it.remove(); // or it.replace(other_msg)
}
{code}

> MessageBatch: removal on iteration is inefficient
> -------------------------------------------------
>
>                 Key: JGRP-2445
>                 URL: https://issues.redhat.com/browse/JGRP-2445
>             Project: JGroups
>          Issue Type: Enhancement
>            Reporter: Bela Ban
>            Assignee: Bela Ban
>            Priority: Major
>             Fix For: 5.0, 4.2.0
>
>
> We oftentimes have iteration through a MessageBatch and removal, e.g.
> {code:java}
> for(Message msg: batch) {
>     if(condition)
>         batch.remove(msg);
>    }
> }
> {code}
> This is inefficient for large batches, as {{MessageBatch.remove()}} iterates through the batch until it finds the message to be nulled.
> It is more efficient to use {{BatchIterator.remove()}}.
> Also include a {{BatchIterator.replace()}} method.
> Pedro's code: [1] https://github.com/pruivo/JGroups/tree/t_msg_batch_iterator



--
This message was sent by Atlassian Jira
(v7.13.8#713008)


More information about the jboss-jira mailing list