java.lang.OutOfMemoryError

R

Rizwan

Hi,

I have written a java program (an EJB) which reads a file (row by row) and
updates some tables based on certain criteria. The program works ok until
the files has 6000 runs. Then the program is failing and giving an error
message :

2004-12-13 15:27:30,101 ERROR [org.jboss.ejb.plugins.LogInterceptor]
Unexpected Error:
java.lang.OutOfMemoryError

I find out where exactly it is failing but dont know how to fix it. My
program read the first row then based on some rules it generates a SQL
statement for this row in a string. I then add it to the batch using
addBatch method of Statement. When I finish reading the file I executes the
batch using executeBatch metohd of Statement. Thats where it is failing. Any
reason? Thanks

Statement stmt = cx.createStatement();
FileReader fr = new FileReader( file );
BufferedReader br = new BufferedReader( fr );
String lineData = null;
String insertStatementSQL = "";
while ( (lineData = br.readLine()) != null ) {
....
stmt.addBatch(insertStatementSQL);
}

int returnValueIntArray[] = stmt.executeBatch();
 
A

Alex Kizub

Statement stmt = cx.createStatement();
FileReader fr = new FileReader( file );
BufferedReader br = new BufferedReader( fr );
String lineData = null;
String insertStatementSQL = "";
while ( (lineData = br.readLine()) != null ) {
....
stmt.addBatch(insertStatementSQL);
}

int returnValueIntArray[] = stmt.executeBatch();

That's exactly memory leak. You collect all statements for whole entire request
in one batch.
Do stmt.executeBatch() inside cycle. For example each 1000 steps.
Alex Kizub.
 
S

srh

ok I change the code like this :
Statement stmt = cx.createStatement();
FileReader fr = new FileReader( file );
BufferedReader br = new BufferedReader( fr );
String lineData = null;
String insertStatementSQL = "";
int recordCount = 0;
while ( (lineData = br.readLine()) != null ) {
.....
if ( recordCount == 1000 ) {
stmt.executeBatch();
stmt.clearBatch();
recordCount = 0;
}
recordCount++;
stmt.addBatch(insertStatementSQL);
}

if ( recordCount > 0 ) {
stmt.executeBatch();
}


It executes the first 1000 successfully but on second 1000 it again
gives the same error message of java.lang.OutOfMemoryError
Am I doing missing something here?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top