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

  • SEARCH
  • Home
  • 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 8367939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:16:30+00:00 2026-06-09T13:16:30+00:00

I have a map that is frequently read but rarely write to. Some operations

  • 0

I have a map that is frequently read but rarely write to. Some operations (can be reading or writing) involves multiple objects that needs to be operated atomically, so I used a ReadWriteLock to improve performance.

Now I have the option to downgrade the concurrent map to a normal hash map, but I am concerned about some of the slow iteration code.

If I downgrade the map, the long iterators to must hold the read lock to avoid concurrent access exceptions. I think this will block the writing threads for too long.

Since some of the iterators are not sensitive to inconsistent data, I can keep the concurrent map so that iterators can be used with concurrent writes. However, this adds unnecessary overhead (from the concurrent map) to operations that are properly using the locks.

Alternatively, I can implement something like a Read-on-write map, where the entire (non-concurrent) map is cloned for a write operation so that existing iterators continues to work outside a read lock.

Obviously, all these methods are valid and the performance depends on the actual code and setup. However, I am wondering is there any study on this (so I don’t have to do the experiments myself)?

  • 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-06-09T13:16:32+00:00Added an answer on June 9, 2026 at 1:16 pm

    I have a map that is frequently read but rarely write to.

    In that case I would consider implementing a copy of write map. e.g.

    private final Map<Key, Value> map = ?* thread safe map */
    private volatile Map<Key, Value> mapCopy = emptyMap();
    
    // when you write
    get lock
    modify map
    take a copy and store it in mapCopy
    release lock
    
    // when you read
    Map<Key, Value> map = this.mapCopy;
    use map
    

    As you can see, you never need to obtain a lock on a read, only on a write.

    If I downgrade the map, the long iterators to must hold the read lock to avoid concurrent access exceptions. I think this will block the writing threads for too long.

    Instead of guess, I suggest you measure it.

    I am wondering is there any study on this

    I wouldn’t take such a study too seriously if it did. As you suggest the result vary based on your situation.

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

Sidebar

Related Questions

I have image map that can I move, but this map will be so
I have one Map that contains some names and numbers Map<String,Integer> abc = new
I have a map that is taller than wide. I noticed that in some
Summary: I have a struct that is read/written to file. This struct changes frequently,
I have a map that i want to update from a separate thread. Im
I have a map that represents a DB object. I want to get 'well
I have a Map that uses a Set for the key type, like this:
I have a map that reads an XML file; it's all very simple and
I have a a map that looks like this: public class VerbResult { @JsonProperty("similarVerbs")
I have a static map that is a private data member. How do I

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.