activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Bain <>
Subject Re: “Usage" and other performance improvements by avoiding CopyOnWriteArrayList.
Date Thu, 07 May 2015 13:05:16 GMT
The other reason a List sometimes gets used is when you want to be able to
arbitrarily order the elements.  If you're using the natural ordering or
can write a comparator, you can use a SortedSet, but if you need them to be
reorderable, I don't know of a Collection that allows arbitrary ordering
but enforces the Set semantic of not allowing duplicates.  List also makes
it easier to ensure that elements stay in insertion order, though it's
possible to get that in other Collections such as a SortedMap<Date, T>.

I don't think that there's a need to arbitrarily reorder any of those three
Collections you're changing, but you need to make sure none of them had
code that relied on inserting elements in sorted order and then having them
maintaining that order.  I could easily see your changes resulting in
jumbled displays in the JMX beans (though maybe there's code that sorts
them at display time so maybe it's not a problem), so make sure you test
that thoroughly.

Also, why are you doing Collections.newSetFromMap( new
ConcurrentHashMap<T,Boolean>()) instead of just new Concurrent
HashSet<T>()?  That seems super convoluted and ultimately not threadsafe
despite appearing to be; am I missing something?

On May 7, 2015 6:38 AM, "Gary Tully" <> wrote:

> those changes look ok to me, as in they won't break anything and you
> have numbers that can make your case. Please splash in a patch or PR.
> On 2 May 2015 at 23:08, Kevin Burton <> wrote:
> > I’ve found 3 places where CopyOnWriteArrayList was being used and causing
> > significant performance impact O(N^2) when using large numbers of queues.
> >
> > Could I get feedback on these 3 changes?
> >
> >
> >
> >
> >
> > In both of these situations, I think a Set is a better idea than a List.
> > First, it’s faster.  Second, why would we want to cousin something twice?
> > That’s the only reason I would think a List would be used instead of a
> Set.
> >
> >
> >
> > --
> >
> > Founder/CEO
> > Location: *San Francisco, CA*
> > blog:
> > … or check out my Google+ profile
> > <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message