Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creatinge a very, very, large Map in Java

Using Java I would like to create a Map that can grow and grow and potentially be larger than the size of the memory available. Now obviously using a standard POJO HashMap we're going to run out of memory and the JVM will crash. So I was thinking along the lines of a Map that if it becomes aware of memory running low, it can write the current contents to disk.

Has anyone implemented anything like this or knows of any existing solutions out there?

What I'm trying to do is read a very large ASCII file (say 50Gb) a line at a time. Each line contains a key and a value. Keys can be duplicated in the file. I'll then store each line in a Map, which is Keys to a List of values. This Map is the object that will just grow and grow.

Any advice greatly appreciated.

Phil

Update:

Thanks for all the comments and advice everyone. With the problem that I described, a Database is the correct, scalable, solution. I should have stated that this is a temporary Map that needs to be created and used for a short period of time to aid in the parsing of a file. In this case, Michael's suggestion to "store only the line number instead of the actual value " is the most appropriate. Marking Michael's answer(s) as the recommended solution.

like image 1000
Phil Avatar asked Sep 27 '11 10:09

Phil


1 Answers

I think you are looking for a database.

like image 191
michael667 Avatar answered Oct 04 '22 22:10

michael667