Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3721196
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:28:23+00:00 2026-05-19T05:28:23+00:00

What would be the least-slow thread-safe mechanism for controlling multiple accesses to a collection

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T05:28:24+00:00Added an answer on May 19, 2026 at 5:28 am

    The exact operations used should determine what is used. However, since the container is largely an abstract type, write it so it works — reliably — then profile, ensure functional requirements, optimize as needed, blah blah 🙂

    Normally, my main use for a “concurrent collection” is a Queue that is used to transfer objects between threads. In this case I start with ConcurrentLinkedQueue if for no other reason than liking the “lock-free” algorithm (this doesn’t mean it will be faster though :-).

    Generally a Queue and/or LinkedList is a good data-structure to append to the end. Depending upon the circumstances including specific usage patterns including: thread contention, number of items removed, how items are removed, etc, a “fast-kill” of all but the start/end might be accomplished faster with a clear (part of AbstractQueue) and item re-addition — ConcurrentLinkedQueue allows both head and tail inspection/manipulation. However, I would urge “keeping it simpler”, writing to a “specific interface contract” and “just use the current approach” until there is strong evidence that a functional-requirement is not met.

    As far as the performance, it really depends upon the particular use-case/operations data-structure characteristics and data-structure implementation. ArrayList may very will be slower than Vector in some cases, and is indeed documented to be. If this performance makes the difference though, something sounds fishy. The article at Java Best Practices – Vector vs ArrayList vs HashSet contains a nice read. Pay attention to the comments as well.

    Edit: Remember that a “concurrent” data-structure generally only implies that a single operation (method call) is atomic (and perhaps not all operations in odd cases!). It may still be required to implement a large-scoped synchronization or other approach to achieve the required level of thread-safety. That is, a h.putIfAbsent(k,v) (from ConcurrentHashMap) is not the same as a if (!h.containsKey(k)) { h.put(k, v); } — as a case-in-point, an issue like this applies to the “clear then add” approach mentioned above.

    Happy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My job would be easier, or at least less tedious if I could come
Would it not make sense to support a set of languages (Java, Python, Ruby,
I would like to associate the last installed version of my Mac OS X
Following on from my last question What is a Stub , I would really
In Nant, I would like to be able to extract the last name of
In the footer of my page, I would like to add something like last
Would it be possible to print Hello twice using single condition ? if condition
Would it be possible to show an image in full screen mode using silverlight.
Would the following SQL remove also the index - or does it have to
Would having a nice little feature that makes it quicker to write code like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.