Results 1 to 5 of 5

Thread: Spring Batch in tomcat : Permgen OutOfMemoryError

  1. #1
    Join Date
    Mar 2011
    Posts
    6

    Default 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 at 10:14 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    349

    Default

    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.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  4. #4
    Join Date
    Mar 2011
    Posts
    6

    Default

    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?

  5. #5
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    349

    Default

    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.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Posting Permissions

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