3
I’m developing a Handle
to a data stream, where periodically events will be launched that are to be captured by a small set of Listeners
from 1 to 5 listeners
.
This set of listeners
do not need to be triggered in registration sequence, it will only be guaranteed that if any excpetion
, is made available on log
, without interrupting the others.
What is the best implementation of the Interface java.util.Set
considering:
- No need for ordination
- The set will be constant (it will not be immutable, but it will not undergo constant changes during execution)
- Recurring calls need not be obtained in the same order
- No Thread Safe Required.
- The set will be small, initially from 1 to 5
listeners
.
Needs to be a
Set
? For such a small ensemble, aArrayList
+ a duplicate check should be good enough... Any other set implementation will likely have a overhead unnecessary in such a small-scale scenario. (which does not mean that it cannot be used, since the difference in performance will be tiny - unless there are many observable objects, each with its own set of listeners - and the convenience of the interfaceSet
can be interesting; in that case I would answer "any one")– mgibsonbr
There is no need to be a Set, the List could also be used, but run the risk of duplicate the set protects me and avoid having to worry about the suggested check.
– Delfino