Why is开发者_如何学Go there Apache's Synchronized Set when we have Collection's SynchronizedSet?
Is it better in any way?
It depends on what you want to do. Apache's synchronized set allows you to get the underlying set. It is probably provide for consistency. The Collections method is standard.
You might consider using one of the concurrent sets like Collections.setFromMap(new ConcurrentHashMap())
, CopyOnWriteArraySet
or ConcurrentSkipListSet
My guess is because it allows you to specify a custom lock object.
The constructor is protected but you can subclass it and pass a custom lock.
精彩评论