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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:39:44+00:00 2026-06-15T13:39:44+00:00

I have enough knowledge on creating Synchronized static objects. However for a Map (Collection)

  • 0

I have enough knowledge on creating Synchronized static objects.
However for a Map (Collection) in Java,

I found default implementations in Java individually (one for Synchronized list and one for for Singleton map).

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Collections.html#synchronizedMap(java.util.Map)
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Collections.html#singletonMap(K, V)

I am thinking of getting the desired result by following implementation

Map<K,V> initMap = new HashMap<K,V>(); 
Map<K,V> syncSingMap = Collections.synchronizedMap(Collection.singletonMap(initMap));

Am i making right sense? Because documentation at oracle shows some warning on this

It is imperative that the user manually synchronize on the returned map when iterating over any of its collection views:

 Map m = Collections.synchronizedMap(new HashMap());
  ...
 Set s = m.keySet();  // Needn't be in synchronized block
  ...
 synchronized(m) {  // Synchronizing on m, not s!
  Iterator i = s.iterator(); // Must be in synchronized block
  while (i.hasNext())
      foo(i.next());
 }

 Failure to follow this advice may result in non-deterministic behavior

How about using ConcurrentMap over this.

Requriement: static synchronized singleton map which will be used by tons of threads for some processing operations

UPDATE

After going through few articles, found that ConcurrentMap is much preferable than HashMap in multi-thread environment
http://java.dzone.com/articles/java-7-hashmap-vs

  • 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-15T13:39:45+00:00Added an answer on June 15, 2026 at 1:39 pm

    Use ConcurrentMap if you are using Java 6+:

    public class MapHolder {
        public static final ConcurrentMap<String, Object> A_MAP = new ConcurrentHashMap<String, Object>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have enough knowledge of git to get by however I've been running
I do not have enough knowledge in JQuery to figure out, where in this
This is probably silly but I don't have enough Elisp knowledge to understand what
I'm no database expert, but I have enough knowledge to get myself into trouble,
Here's where I have enough knowledge to be dangerous. I'm working on a web
I don't have enough C knowledge to work out the right thing to do
Do async operations with callbacks increase the stack size? I don't have enough knowledge
I don't have enough knowledge about PHP to handle this situation. What I want
Ok i just don't have enough knowledge for this simple script apparently. Basically, in
I have the following Storyboard: I dont have enough rep points yet for images

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.