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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:55+00:00 2026-05-25T21:37:55+00:00

I ‘ve been doing some performance checks with one HashMap object in my code

  • 0

I ‘ve been doing some performance checks with one HashMap object in my code and discovered that it slows down adding objects inside at around 2000-2400 objects. In fact when it arrives to 2400 objects circa, it remains blocked and doesn’t admit more entries. Is there a limit in this kind of objects that when they’ve been kept in memory don’t admit more entries until they are emptied someway or recycled?

Thank you very much.

  • 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-25T21:37:56+00:00Added an answer on May 25, 2026 at 9:37 pm

    The only thing I can think of which might explain the problem is if your objects are very large and you are almost running out of heap. When this happens the JVM can stop for increasingly long period of time trying to clean up. In Java 6 it tries to detect this before it gets really bad and throw an OutOfMemoryError (before it has completely run out but it failed to clean up much) Java 5.0 doesn’t do this.

    It would explain why things speed up again when you discard a few objects.


    The standard implementation of HashMap is limited to around 750 million entries (depending on how you use it e.g. your load average) The maximum capacity it can have is 2^30 (one billion) and with a load factor of 0.75f (~750m entries) it will try to grow the underlying array to double this size which it cannot do. (As the maximum size is Integer.MAX_VALUE)

    You can use LinkedHashMap as a cache, evicting the “eldset” entry based on a rule you have to provide.

    However, unless the HashMap is synchronized it will not block. If it going to fail it will throw an exception.

    The only consistent way to get a Map to block this way is to have a deadlock.

    Another way this can happen is if you are using the same map in two threads in an unsafe manner. In this case the behaviour is undefined, however I have seen it cause problem in the JVM (very rarely) and even “hang” the thread involved. Even if this were the case, I would expect it to have on a growing of the HashMap with a default load factor this would be 3072 (i.e. 4096*0.75) rather than the value you see.


    Even having a bad hashCode implementation would not explain this problem.

    static class BadHash {
        @Override
        public int hashCode() {
            return 1;
        }
    }
    
    public static void main(String... args) {
        Map<BadHash, Boolean> map = new HashMap<BadHash, Boolean>();
        for (int i = 0; i <= 100000; i++) {
            if (i % 10000 == 0) System.out.println(i + ": " + new Date());
            map.put(new BadHash(), true);
        }
    }
    

    prints the following in 14 seconds.

    0: Mon Sep 26 12:23:39 BST 2011
    10000: Mon Sep 26 12:23:39 BST 2011
    20000: Mon Sep 26 12:23:39 BST 2011
    30000: Mon Sep 26 12:23:40 BST 2011
    40000: Mon Sep 26 12:23:41 BST 2011
    50000: Mon Sep 26 12:23:42 BST 2011
    60000: Mon Sep 26 12:23:44 BST 2011
    70000: Mon Sep 26 12:23:46 BST 2011
    80000: Mon Sep 26 12:23:48 BST 2011
    90000: Mon Sep 26 12:23:51 BST 2011
    100000: Mon Sep 26 12:23:53 BST 2011
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I am trying to create a RegEx expression that will successfully parse the following
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i got an object with contents of html markup in it, for example: string
The problem with unsigned char. I am reading a PPM image file which has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm creating a web service to transfer json to an iPhone app. I'm using
I need to clean up various Word 'smart' characters in user input, including but

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.