Java has tons of different Collections designed for concurrency and thread safety, and I'm at a loss as to which one to choose for my situation.
Multiple threads may be calling .add()
and .remove()
, and I will be copying this list frequently with something like List<T> newList = new ArrayList<T>(concurrentList)
. I will never be looping over the concurrent list.
I thought about something like CopyOnWriteArrayList
, but I've read that it can be very inefficient because it copies itself every time it's modified. I'm hoping to find a good compromise between safety and efficiency.
What is the best list (or set) for this situation?