Results 1 to 10 of 16

Thread: OutOfMemoryError - File read & File write

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    174

    Default OutOfMemoryError - File read & File write

    Hello All,

    I am using a simple job that reads the file and writes the read line to another file (just doing a volume testing with spring batch). The input file is more than 7GB.
    I have file reader (FlatFileItemReader) and a file writer (FlatFileItemWriter). Is there a limitation on the number of records that can be processed at a single time (I suppose not).

    Here is the error, if someone can hint me know what might be wrong, I can check it out:

    Code:
    Caused by: java.lang.OutOfMemoryError: Java heap space
            at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.
    java:99)
            at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:518
    )
            at java.lang.StringBuffer.append(StringBuffer.java:307)
            at java.io.BufferedReader.readLine(BufferedReader.java:345)
            at java.io.BufferedReader.readLine(BufferedReader.java:362)
            at org.springframework.batch.item.file.separator.ResourceLineReader$Stat
    e.readLine(ResourceLineReader.java:225)
            at org.springframework.batch.item.file.separator.ResourceLineReader.read
    Line(ResourceLineReader.java:134)
            at org.springframework.batch.item.file.separator.ResourceLineReader.read
    (ResourceLineReader.java:120)
            at org.springframework.batch.item.file.FlatFileItemReader.readLine(FlatF
    ileItemReader.java:103)
            at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFil
    eItemReader.java:266)
            at org.springframework.batch.item.support.AbstractBufferedItemReaderItem
    Stream.read(AbstractBufferedItemReaderItemStream.java:92)
            at org.springframework.batch.item.support.DelegatingItemReader.read(Dele
    gatingItemReader.java:61)
            at org.springframework.batch.core.step.item.BatchListenerFactoryHelper$1
    .read(BatchListenerFactoryHelper.java:67)
            at org.springframework.batch.core.step.item.SimpleItemHandler.doRead(Sim
    pleItemHandler.java:88)
            at org.springframework.batch.core.step.item.SimpleItemHandler.read(Simpl
    eItemHandler.java:80)
            at org.springframework.batch.core.step.item.SimpleItemHandler.handle(Sim
    pleItemHandler.java:66)
            at org.springframework.batch.core.step.item.ItemOrientedStep$2.doInItera
    tion(ItemOrientedStep.java:390)
            at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult
    (RepeatTemplate.java:346)
            at org.springframework.batch.repeat.support.RepeatTemplate.executeIntern
    al(RepeatTemplate.java:212)
            at org.springframework.batch.repeat.support.RepeatTemplate.iterate(Repea
    tTemplate.java:143)
            at org.springframework.batch.core.step.item.ItemOrientedStep.processChun
    k(ItemOrientedStep.java:383)
            at org.springframework.batch.core.step.item.ItemOrientedStep$1.doInItera
    tion(ItemOrientedStep.java:251)
            at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult
    (RepeatTemplate.java:346)
            at org.springframework.batch.repeat.support.RepeatTemplate.executeIntern
    al(RepeatTemplate.java:212)
            at org.springframework.batch.repeat.support.RepeatTemplate.iterate(Repea
    tTemplate.java:143)
            at org.springframework.batch.core.step.item.ItemOrientedStep.doExecute(I
    temOrientedStep.java:231)
            at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep
    .java:172)
            at org.springframework.batch.core.job.SimpleJob.execute(SimpleJob.java:1
    00)
            at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run
    (SimpleJobLauncher.java:86)
            at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecut
    or.java:49)

    I have a java object with one bytearray property. In my FieldSet Mapper I read first 100 bytes of the input line into this byte array and then in my writer (with PassThrough fieldset creator), I do a new String(byteArray) and write it out.

    I also tried with that java object property as String. I am using Spring Batch 112.

    Please let me know your thoughts. Also let me know whether there is a way I can speed this.

    Thanks!!

  2. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    Spring Batch doesn't store much intermediate state, unless you are doing something crazy with ExecutionContext. It's practically impossible to diagnose OOM from a stack trace, so maybe you can share some more details?

  3. #3
    Join Date
    Dec 2008
    Location
    Bangalore
    Posts
    25

    Default

    Try to set JVM memory size like java -Xms500m.

  4. #4
    Join Date
    Mar 2009
    Posts
    6

    Question The same problem

    I also encounter this problem recently, The input file is too large(maybe 2 million lines), and the OutOfMemory Error happens, Is any solution or findings about this problem?

  5. #5
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    I don't have any problems with large files (as I said before Spring Batch is intentionally not storing very much intermediate data in memory). You need to share some more details of what you are doing.

  6. #6
    Join Date
    Apr 2008
    Posts
    174

    Default

    Here is what I encountered, even I was under the same impression that Spring batch is failing for huge files but only later to find out that somewhere in the middle of my file there was no "line feeder" or "next line character", and when I debugged through the code I found that Spring batch makes a call "readLine" internally to get the next line and the parse it.

    Since the readLine relies on next line character, which was missing somewhere in the middle, it was trying to load the whole line (almost rest of the file) into memory as a single line which eventually caused it to fail and throw out of memory exception.

    Again this was the experience I had and spend about couple of days to figure out the issue, hope you dont waste that much time. Additionally, this is what I encountered and I can not guarantee that you are also having the same issue, but worth checking it.!!! :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •