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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:27:04+00:00 2026-06-01T09:27:04+00:00

I was going to implement some code which needs a synchronized data structure. I

  • 0

I was going to implement some code which needs a synchronized data structure. I came up with HashTable and Collections.synchronized(HashMap). I wouldn’t be needing ConcurrentHashMap for this. I was wondering which one of the two would be better.

PS : I will be calling a lot of getter of this object and they would not be at the same time. So their is no problem with concurrency issue also.

  • 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-01T09:27:06+00:00Added an answer on June 1, 2026 at 9:27 am

    ConcurrentHashMap is much more scaleable: http://www.javamex.com/tutorials/concurrenthashmap_scalability.shtml

    HashTable and Collections.synchronized(HashMap) provide with the same performance, but they are conditionally thread-safe (i.e. they are not fully thread-safe)

    If there are a lot read operations, I would recommend to wrap it with read-write locks:

    public class MyHashMap<K, V> extends HashMap<K, V> {
         private final ReadWriteLock lock = new ReentrantReadWriteLock();
    
        @Override
        public V put(K key, V value) {
            final Lock w = lock.writeLock();
            w.lock();
            try {
                return super.put(key, value);
            } finally {
                w.unlock();
            }
        }
    
        @Override
        public V get(Object key) {
            final Lock r = lock.readLock();
            r.lock();
            try {
                return super.get(key);
            } finally {
                r.unlock();
            }
        }
        .... // the same approach distinguishing read and write operations
    
    }
    

    UPDATE:

    I will be calling a lot of getter of this object and they would not be at the same time

    It doesn’t guarantee that you don’t need synchronization.

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

Sidebar

Related Questions

I'm trying to implement some code to import user's data from another service via
I'm going to implement an web app in gae. I was wondering which is
In my code, I need to keep track of some pages which are being
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
I'm going to implement license key generator on my website but I've very few
I'm going to implement my strings with internationalization in my Android app. I have
I'm going to implement this The layout is exactly like it is tables so
I'm going to implement a searching function for a sms managing system, where the
What's the best way going forward to implement Wake on LAN using C#? The
Going through some of my older Delphi projects and upgrading them to D2009, 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.