B
Brock Heinz
Hello All,
I've done quite a bit of research on this one and I'm still stumped.
I have an application that reads a text file (up to 100MB in size) one
line at at time, converts the line to XML using Castor (each line is a
specific record) and then sends a JMS message for that line. After
validating the file one line at a time (never reading the entire
contents into memory), I am then confident I can perform the Castor
transformation / send operation. I'm doing something like the
following:
BufferedReader reader = new BufferedReader(new FileReader(validFile));
//for each line in the file
for (String line; (line = reader.readLine()) != null {
//perform transformation and send
IMessage message = transformer.createMessage(line, msgSelector);
sendMessage(message);
messageSentCount++;
//perform cleanup / logging every 500th message
if (messageSentCount % 500 == 0) {
log.debug("sent message: "+messageSentCount);
log.debug(" - Garbage collecting.");
try {
this.finalize();
} catch (Throwable t) {
log.warn("Could not finalize - keep on reading anyhow");
}
}
}
reader.close();
Does anyone see any problems with reading the files one line at a time
in this manner (using the readLine() method)? I seem to hit an
OutofMemoryException right around line 315,000. Is the readLine()
method interally not efficient to use?
In the archives I've seen the approach of reading chunks of the file
with a buffer, and then determining each line by seaching for carriage
returns or line breaks. Anyone have any thoughts on this?
Any help would be greatly appreciated.
Thanks,
Brock
I've done quite a bit of research on this one and I'm still stumped.
I have an application that reads a text file (up to 100MB in size) one
line at at time, converts the line to XML using Castor (each line is a
specific record) and then sends a JMS message for that line. After
validating the file one line at a time (never reading the entire
contents into memory), I am then confident I can perform the Castor
transformation / send operation. I'm doing something like the
following:
BufferedReader reader = new BufferedReader(new FileReader(validFile));
//for each line in the file
for (String line; (line = reader.readLine()) != null {
//perform transformation and send
IMessage message = transformer.createMessage(line, msgSelector);
sendMessage(message);
messageSentCount++;
//perform cleanup / logging every 500th message
if (messageSentCount % 500 == 0) {
log.debug("sent message: "+messageSentCount);
log.debug(" - Garbage collecting.");
try {
this.finalize();
} catch (Throwable t) {
log.warn("Could not finalize - keep on reading anyhow");
}
}
}
reader.close();
Does anyone see any problems with reading the files one line at a time
in this manner (using the readLine() method)? I seem to hit an
OutofMemoryException right around line 315,000. Is the readLine()
method interally not efficient to use?
In the archives I've seen the approach of reading chunks of the file
with a buffer, and then determining each line by seaching for carriage
returns or line breaks. Anyone have any thoughts on this?
Any help would be greatly appreciated.
Thanks,
Brock