posted 21 years ago
A number of miscellaneous points.
As all the provisos already indicated, you're not giving us enough information on the things you need to do with the data to give an unequivocal answer. To add even more options to what Jim said, if the data is unique and especially if you need to remove items from the list by value, a HashSet may be the answer. We can keep on expanding this list until we've had every single container in the Collections framework. They all exist for good reasons and each has its own domain.As Jim mentioned too, Collections.synchronizedCollection(); and friends almost never don't cut it when you need code to be threadsafe. It makes the collection threadsafe alright (although not the process of iterating over it), but that is unlikely to make your code threadsafe. You probably don't need synchronization on the little Collection methods, but on the coarser-grained, composite operations that you implement. In that case, a synchronized Collection won't buy you anything and just lure you into a false sense of security.This is also the solution to your problem. You don't want to synchronize on more than one object at a time, as acquiring multiple locks immediately introduces the potential for deadlock. Just don't bother with synchronized Collections. Wrap the Collection inside your own object that does the high-level data manipulation, and synchronize that (synchronized methods tend to be more readable than synchronized blocks, so use them where you can).Don't use Hashtable, Vector, Stack and Enumeration if you can help it. Their synchronization by and large just lowers performance, their APIs are confusing, they do site outside the Collections framework, and they are generally obsolete even though they aren't deprecated.HTH
- Peter
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd