Solved

Are Hashtable and Treeset heavy on the resources (memory)

Posted on 2011-03-06
8
724 Views
Last Modified: 2012-05-11
Hi,
I'm developing an application where I'm planning to use two hashtables with about a size of 1000 each. In the value, each value will be storing a treeset as an object containing about 1000 values. What I'd like to know is if this hashtable and treeset setup with such a large size makes the design very resource heavy?

As per my understanding , Hashtables usually start with a default initial capacity of about 11 (or 16). So 1000 in this case might mean a lot. Is that correct?

Thanks.
0
Comment
Question by:orazen12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 92

Accepted Solution

by:
objects earned 167 total points
ID: 35053459
0
 
LVL 47

Expert Comment

by:for_yan
ID: 35053995
On most modern computers where you can have several  hundred megabytes of memory and maybe even
more than 1 GB for your application these requirements do not seem to be prohibitive - you'll probably
have to increase the amount of allocated memory  in the options for virtual machine, say
-Xmx512M  or someting like that.
0
 

Author Comment

by:orazen12
ID: 35054596
Thanks ObJects.

For_Yan,
My server has 1 GB memory out of which 750MB is already being used (atleast that's what it is showing me in the webmin). Do you mean to say I'd need approx 1GB for this kind of operation or it should be ok with with my current system. It is doing a lot of other stuff too. Is there a way to check how much memory my system is using for this kind of operation?

Thanks.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:darren-w-
ID: 35055068
Hi,

Your computer would start using the swap if ram  is full, and this would then in turn slow down processing time as read-writes  from disk will be slower, apart from this it should not be a problem.

Darren
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 166 total points
ID: 35055113
I think the best way is first to write it in a straightforward way using all hashtables you need - make sure you are not getting java out of memory messages (provide sufficiently big number in -Xmx) and then observe - if you feel that your performance is too slow for your business  purposes, then try to monitor with your system means if your program is indeed doing a lot of memory swaps, then start thinking how to design your program to reduce memory size. My guess is that you'll not see too much swapping.
0
 
LVL 10

Assisted Solution

by:gordon_vt02
gordon_vt02 earned 167 total points
ID: 35058193
What kind of values are you storing?  The overhead of each Hashtable and TreeSet is fairly minimal so you need to figure out how much storage each object in the TreeSet requires and then you can estimate the amount of memory required.

Sk = memory for hash key
Se = memory for each tree entry
n = number of hash entries
m = number of tree set entries

App Mem = n * (Sk + (m * Se))

So, if your hash key is a long (8 bytes) and your TreeSets contain ints (4 bytes), with 1000 sets of 1000 items you would use:

1000 * (8 + (1000 * 4)) = 4,000,800 bytes = ~3.8 MB

If your value objects contain more complex data structures, especially variable length members like strings or arrays, you can come up with a good range and evaluate a worst-case scenario to make sure you have enough memory.  You aren't talking about a whole lot of data objects though, so unless each object is pretty big, you probably won't even need to modify the default JVM memory settings, and setting it to use at most the 250MB you have remaining should give plenty of room without swapping.
0
 
LVL 10

Expert Comment

by:gordon_vt02
ID: 35058201
Oops, flipped the 0 and 8 in that calculation.  Should be 4,008,000 bytes = ~3.8 MB.
0
 

Author Closing Comment

by:orazen12
ID: 35125537
Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 136
servlet example 17 59
Selenium docs api java index 3 69
IBM TS2900 (3572) Tape Autoloader Java? 12 61
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question