java.lang.OutOfMemoryError w.r.t. HashMap

Hi there,

My requirement is to read a flat file of size 300 MB, the contents i read has to be stored as key value pair.

The current colleciton that i have used is the HashMap.

While when the data is pushed into the HashMap, i m getting java.lang.OutOfMemoryError

The size of the HashMap at which i get the OutOfMemoryError is 165451

Can u suggest for any other collection or do i need to go with customized userdefined methods.

Array of HashMap or HashMap of HashMap can solve issues, but is there any specifc collection to resolve this.

More over, in future the flat file size could increase massively.

Shan

[670 byte] By [ShanGka] at [2007-11-27 1:56:51]
# 1
A HashMap can hold all items. That isn't the problem. The problem is that the VM isn't allowed to allocate the memory that it needs. Increase the available VM memory by using the VM argument -Xmx (e.g. -Xmx512M)Kaj
kajbja at 2007-7-12 1:31:44 > top of Java-index,Java Essentials,Java Programming...
# 2

> My requirement is to read a flat file of size 300 MB,

> the contents i read has to be stored as key value

> pair.

That will require at least 300 MB of RAM.

By default the JVM is given only 64MB so the first thing you need to do is increase the heap memory setting. This is done by passing command line arguments to the "java" program launcher:

-Xms<size>set initial Java heap size

-Xmx<size>set maximum Java heap sizeFor the syntax of specifying "<size>" see

http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html

> More over, in future the flat file size could

> increase massively.

Then don't even try to load the whole thing to memory. Loading hundreds of megabytes of data into memory is always a bad idea. Maybe you could use a simple database (MySQL?) or change the file format so that you can use RandomAccessFile or a MappedByteBuffer.

jsalonena at 2007-7-12 1:31:44 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks all.
ShanGka at 2007-7-12 1:31:44 > top of Java-index,Java Essentials,Java Programming...