Announcement Announcement Module
No announcement yet.
reuse of job with different parameters outofmemoryexception - heap space Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • reuse of job with different parameters outofmemoryexception - heap space

    Hi all,

    I create a job that reads a file and processes it and deletes it

    I reuse the job passing it to JobLauncher again but with a new parameters object with new timestamp

    When i run this for a lot of times say a few hundred files I get the above exception.

    I have removed all the code that the job does so it is literally is sending a new job to the launcher and editing parameters and launching it and it does nothing and finishes.

    I still get the same error

    Can I use a job in this way using it over again with different parameters?

    While (True)
    //poll for new files in dir add to rdifiles arraylist
    Resource r = new FileSystemResource(new File((String) rdifiles.get(i)));
    ExecutionContext e = new ExecutionContext();      
    JobParameters jobParameters = new JobParametersBuilder.addDate("now", new Date()).addString("JobType", "RDI").toJobParameters();
      , jobParameters).getStatus();

  • #2
    What kind of JobRepository are you using?


    • #3
      Here is the setup for job repository

      Cheers for help!

      <bean id="transactionManager" class="" />
      	<bean id="jobRepository" class="">
      		<property name="transactionManager" ref="transactionManager"/>


      • #4
        The MapJobRepository keeps all of the information in memory. Since you are repeatedly launching jobs, you are adding to the repository, and, thus, using more memory each time until you run out.


        • #5
          So is there a way of clearing the repository memory - an object that uses less memory.

          Or something like the last 50 jobs etc.

          Whats best course of action


          • #6
            The best course of action is using a database to store your repository information.

            If you still use the MapJobRepositoryFactoryBean, then you can use its static method clear() that will clear all of the data.


            • #7
              I have just tried this littleray after each job finishes to call


              Im still getting the same issue

              I add to a list of 1000 files that need to process

              Then change resources run the job
              change the resource run the job etc

              2009-07-06 11:13:35,183 ERROR main [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step: class java.lang.OutOfMemoryError: Java heap space>
              java.lang.OutOfMemoryError: Java heap space
              	at java.util.Arrays.copyOf(Unknown Source)
              	at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
              	at java.lang.AbstractStringBuilder.append(Unknown Source)
              	at java.lang.StringBuffer.append(Unknown Source)
              	at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(
              	at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(
              	at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(
              	at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(
              	at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(
              	at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(
              	at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(
              	at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(
              	at org.springframework.batch.core.step.AbstractStep.execute(
              	at org.springframework.batch.core.job.AbstractJob.handleStep(
              	at org.springframework.batch.core.job.flow.FlowJob.access$0(
              	at org.springframework.batch.core.job.flow.FlowJob$JobFlowExecutor.executeStep(
              	at org.springframework.batch.core.job.flow.FlowJob.doExecute(
              	at org.springframework.batch.core.job.AbstractJob.execute(
              	at org.springframework.core.task.SyncTaskExecutor.execute(
              	at com.edfe.orchard.correspondenceRoutingService.ContextSetter.main(


              • #8
                Also is there a limmit on the size of the file that can be read by a flat file item reader

                This might be cause of issue

                I have a 17 meg text file that im reading line by line

                If it tries to buffer the whole thing?

                At moment have a multi line record reader setup with a delegate to flat file reader that reads say 10 lines to make up complete object.


                • #9
                  What is your commit interval? The framework holds the entire chunk in memory as it writes, so you will run out of memory if your commit interval is too large.


                  • #10
                    Just changed the commit interval to one and i still get same effect

                    I also ahve property "StartLimit" which i have tried low and high


                    • #11
                      I don't have any problem launching simple jobs. From the stack trace it looks like SimpleWriter is doing something with a StringBuffer. Can we see the implementation?


                      • #12
                        Correct it was the fact the writer which was creating a buffer of every message so i would have like a few thousand of them.

                        Sorted this now.

                        Thank you for your help.


                        • #13
                          Hi Dave,
                          Found this thread while having the same issue as the original poster.

                          I went through the MapJobRepositoryFactoryBean code and if I understood it correctly, job instances and daos are stored in static collections. Does this mean that even if we destroy the Spring context for each run of Batch job, we are still retaining the collections since they are static? Are they not tied to the Spring life cycle of beans?

                          So we have to always call 'clear' to ensure that we get a fresh repo and cleared memory (unless of course we restart the application and get a fresh jvm). Do you think it would be better that Spring Batch will automatically clear these collections?


                          On second thought, MapJobRepositoryFactoryBean should only be used for testing.