OutOfMemoryError

friends,

I am retrieving records (500,000 and more) from, one or more, databases using two SQL queries. I compare each record and if it I record the comparison result.

Now I am having following problems

1.How do I write to a file so many records and save myself from getting the above error.

2.How do retrieve Rows in batches or remove few rows from result set once there task is finished.

3.How do I catch OutOfMemoryError without terminating or affecting the memory. is there any way to call garbage collection from my program itself. I have tried using more memory for virtual MC but i think its an temporary solution.

[672 byte] By [nirmitdesai07] at [2007-9-30 4:10:41]
# 1

you can't catch outofmemoryerror. First you have to check teh heap size you have set for your java process. It might be possible to get rid of loitered objects in your code. or you can divide you db calls into several statements... try more debugging with Runtime.freeMemory() where the goes for.

naimdjon at 2007-6-29 17:55:05 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2
If you happened to store that many objects in the memory, you could reconsider your application.
BIJ001 at 2007-6-29 17:55:05 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Actually, you can catch out of memory errors. There are some sticky issues, but you can.

But you cannot KEEP the objects in memory which caused the error, so that won't help you much.

You are looking for the -Xmx[size] option. First, you should read this page:

http://www.onjava.com/pub/a/onjava/2001/08/22/optimization.html

but since you probably won't do that first :~), you could try starting your code with

java -Xmx256M className

A better idea would be to NOT get 500,000 records, if you can help it. But I'm sure you knew that :~)

Good luck,

Geoff

Geoff_Granum at 2007-6-29 17:55:05 > top of Java-index,Java HotSpot Virtual Machine,Specifications...