I need a data structure that is a LinkedHashMap and is thread safe.
How can I do that ?
See Question&Answers more detail:osI need a data structure that is a LinkedHashMap and is thread safe.
How can I do that ?
See Question&Answers more detail:osYou can wrap the map in a Collections.synchronizedMap to get a synchronized hashmap that maintains insertion order. This is not as efficient as a ConcurrentHashMap (and doesn't implement the extra interface methods of ConcurrentMap) but it does get you the (somewhat) thread safe behavior.
Even the mighty Google Collections doesn't appear to have solved this particular problem yet. However, there is one project that does try to tackle the problem.
I say somewhat on the synchronization, because iteration is still not thread safe in the sense that concurrent modification exceptions can happen.