If i'm only doing read operations to a collection using multiple threads,
is it more efficient to use the concurrent collection or the standard unsynchronized ones?
Assume the data structure was created and filled using only a single thread.
If you guarantee that no write operation occurs after you start reading (basically the collection and (important) the elements of the collection are immutable), you should definitely use the non synchronized collections which are much faster.
And just to help make doubly extra sure (and to notify any other coders who may work on your application) that the collection should not be modified once filled you should probably wrap the collection in an 'unmodifiable' version. See The Collections class for methods.
Joined: Jul 09, 2008
Steve is right. All developers should be aware of the thread safeness of different classes. In order to achieve this you could use some standard annotations like @ThreadSafe, @Immutable, @GuardedBy. If you can find a good way of making these annotations visible in JavaDocs would be even better.
subject: Concurrent Collections vs Unsynchronized Collections