My thread pool has a fixed number of threads. These threads need to write and read from a shared list frequently.
So, which data structure (it better be a List, must be monitor-free) in java.util.concurrent package is best in this case?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The only
Listimplementation injava.util.concurrentis CopyOnWriteArrayList. There’s also the option of a synchronized list as Travis Webb mentions.That said, are you sure you need it to be a
List? There are a lot more options for concurrentQueues andMaps (and you can makeSets fromMaps), and those structures tend to make the most sense for many of the types of things you want to do with a shared data structure.For queues, you have a huge number of options and which is most appropriate depends on how you need to use it: