Announcement Announcement Module
Collapse
No announcement yet.
Spring Batch in tomcat : Permgen OutOfMemoryError Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Batch in tomcat : Permgen OutOfMemoryError

    I am launching spring Batch jobs within a tomcat servlet container. Every time i launch a job i start the spring batch appcontext and finally i close it. Most of my beans i am loading are singletons. By starting and closing context every time i run a job am i creating lot of proxy classes that are not being garbage collected or stored in Permgen.

    After running multiple batch jobs i got java.lang.OutOfMemoryError: PermGen space errors

    Below is the code i am using to start and close my appcontext

    I would like to know if i am doing anything wrong, and if there is an efficient way to accomplish the same

    public void runJobLauncher( String jobPath, String jobIdentifier, String... parameters ) throws Exception{
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( jobPath );
    try{
    context.getAutowireCapableBeanFactory().autowireBe anProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    Job job = (Job) context.getBean( jobIdentifier );
    JobParameters jobParameters = new DefaultJobParametersConverter().getJobParameters( StringUtils.splitArrayElementsIntoProperties( parameters, "=" ) );

    JobExecution jobExecution = jobLauncher.run(job, jobParameters);
    ExitStatus exitStatus = jobExecution.getExitStatus();
    }finally{
    context.close();
    }

    }
    Last edited by dgiridhar; Dec 13th, 2012, 11:14 PM.

  • #2
    I am launching spring Batch jobs within a tomcat servlet container. Every time i launch a job i start the spring batch appcontext and finally i close it
    Don't... You should never do this as, as you noticed, in the end you will run into problems with memory, database connections, concurrency. Simply reuse a single instance.

    Also if classes aren't cleaned it means references to those things are kept somewhere so you probably need to check your code.

    Comment


    • #3
      Why are you creating a new context every time you launch a job when running in a container? In an environment like this you typically will bootstrap a single context with a JobRegistry that you can pull jobs from and execute them as required. Bootstrapping a new context every time is going to cause you many issues.

      Comment


      • #4
        My thought was that i bring up the appcontext for bath jobs only when requried and close it at the end of the job. Is it wrong for me to assume that every thread that starts a job will have its own application context and hence will not have any concurrency or connection issues?

        Comment


        • #5
          Take a look at the job loader configuration in Spring Batch Admin. That is a good example of the right way of loading jobs to be executed in a container.

          Comment

          Working...
          X