I need to maintain a list of objects in a multi-threaded environment. I have read about CopyOnWriteArrayList
and it seemed to be an option to go for. The problem is, I needed to sort the list, too. I cannot use Collections.sort()
for CopyOnWriteArrayList
as it doesn't support the set()
operation. I have found few ways to sort the CopyOnWriteArrayList. But performance-wise, they don't look to be good.
My question: is there an alternative data-structure which will come handy in this situation? Basically, I need to keep a sorted list in an multi-threaded environment. A list adapter will use that data structure. So, it should have provide methods like "get(position)".
I recently read about another data structure ConcurrentSkipListSet
. Can anyone explain what are the pros and cons of it? Will it be a good fit for my problem?