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 6386661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:03:14+00:00 2026-05-25T03:03:14+00:00

I have gone through the below links Problem with synchronizing on String objects? and

  • 0

I have gone through the below links
Problem with synchronizing on String objects?
and
http://illegalargumentexception.blogspot.com/2008/04/java-synchronizing-on-transient-id.html

Now my question:

  1. I have a map where userid and a list of some properties are maintained
  2. when we come across new userid we will create an entry in the map
  3. if the userid is already present we will add some properties to the value

instead of synchronizing on the whole map, we tried to synchronize on the userid and that results in some random behavior, if we use intern() it works
the approach in the second link also works

Questions:

  1. in the second approach we are still locking the whole map when getting key
  2. is there some other way of synchronization so that the map access is synchronized based on userid alone
  3. what is the best way to do this?
  • 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-25T03:03:15+00:00Added an answer on May 25, 2026 at 3:03 am

    The best way is to use a ConcurrentHashMap from the java.util.concurrent package. This class has everything you need built right in. Don’t re-invent the wheel!

    Note: Thilo is right: You must use ConcurrentHashMap’s special thread-safe version of put: putIfAbsent()

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

Sidebar

Related Questions

How to write joins in django,i have gone through below django documentation ,but joins
I have gone through their developer guide but haven't been able to find a
Over the years as I have gone through school and been working in the
I have gone through various books on stateful and stateless session bean and how
I have gone through the Android guide for other IDEs , and I've got
I have gone through various articles, but I still do not know why instanceof
I have gone through the several samples in the web.I understood to protect software
while reading cocoa fundamental guide i have gone through: (void)addObserver:(id)notificationObserver selector:(SEL)notificationSelector name:(NSString *)notificationName object:(id)notificationSender
currently using jq 1.4.2 And i have gone through this forum and other forums
I have gone through all available study resources in the internet as much as

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.