What would be the least-slow thread-safe mechanism for controlling multiple accesses to a collection in Java?
I am adding objects to the top of a collection and i am very unsure what would be the best performing collection. Would it be a vector or a queue? I originally thought an ArrayList would be fast but i ran some experiments and it was very slow.
EDIT: In my insertion testing a Vector delared using volatile seems to be the fastest?
See collections in java.util.concurrent
.
The best algorithms avoid shared state as much as possible. It sounds like you are new to multi threaded programming in java. Why not just pick something that you know will be correct.... Then see how much synchronisation there is, then see if that is a problem...then see if you can find a faster way to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With