activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Burton <bur...@spinn3r.com>
Subject Re: “Usage" and other performance improvements by avoiding CopyOnWriteArrayList.
Date Fri, 08 May 2015 17:33:00 GMT
On Thu, May 7, 2015 at 6:05 AM, Tim Bain <tbain@alumni.duke.edu> wrote:

> 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.


Yes.  And strictly speaking, in set theory, the order is irrelevant.  Sets
are equivalent if they share the same members.  But I’m not sure Java sets
are supposed to be identical set theoretic sets.


>
> 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.
>

Ah.  I’ll take a look at that but didn’t see this yet.

I’m also expecting the tests to find any irregularities.. hopefully.


>
> 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?
>


I don’t think there is a ConcurrentHashSet… There’s a ConcurrentHashMap but
no ConcurrentHashSet.. The work around is to use newSetFromMap …

I got bit by that too.  I just always assumed there was a ConcurrentHashSet
but the above newSetFromMap works. It’s a lightweight Set implementation.
In the JDK it’s literally just a 10 line decorator.

-- 

Founder/CEO Spinn3r.com
Location: *San Francisco, CA*
blog: http://burtonator.wordpress.com
… or check out my Google+ profile
<https://plus.google.com/102718274791889610666/posts>

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