CONCURRENT SET

Hello,

Is there any concurrent implementation of HashSet?

CopyOnWriteArraySet is not useful for me (I'll have a lot of threads reading and writing on this set)

And ConcurrentSkipListSet keeps the order of the elements, and for me the order is not important (as a normal set).

And I wouldn't want to use a Collections.synchronizedSet(...), because of too much locking.

Any alternative?

Thanks.

[438 byte] By [jbalagueroa] at [2007-11-27 0:23:27]
# 1
Just use ConcurrentHashMap and put in a dummy object for the value. Take a look at the source code for HashSet, this is exactly what HashSet does.
Caffeine0001a at 2007-7-11 22:19:10 > top of Java-index,Core,Core APIs...
# 2

If you don't want any of the standard solutions, what are your special locking needs? Chances are you will need to implement your own locking scheme.

BTW, are you sure Collections.concurrentSet() won't do? Have you profiled a solution based on that and concluded that its locking is slowing your application down?

Herko_ter_Horsta at 2007-7-11 22:19:10 > top of Java-index,Core,Core APIs...
# 3

Hello,

Yes, I've made test cases not with Set but with ConcurrentHashMap and Hashtable/Collections.synchronizedMap(). With hundreds of threads getting/putting in these collections (as my app does), the behaivour of ConcurrentHashMap is much better than the other solutions.

That's why I thought that with Collections.synchronizedSet against any concurrent implementation of Set the conclusion would be the same.

But as Caffeine says, I can try with ConcurrentHashMap asking for the key and ignoring the value.

Thanks.

jbalagueroa at 2007-7-11 22:19:10 > top of Java-index,Core,Core APIs...
# 4
Just one more thing. For the same reason, is there any concurrent implementation of LinkedHashMap? I've seen concurrent implementations of HashMap and TreeMap but not for LHM.Thanks a lot.
jbalagueroa at 2007-7-11 22:19:10 > top of Java-index,Core,Core APIs...