Results 1 to 5 of 5

Thread: Variables values remain in memory after Spring Batch Job execution

  1. #1
    Join Date
    Oct 2012
    Location
    Madrid
    Posts
    20

    Default Variables values remain in memory after Spring Batch Job execution

    My project has several processes that are been executed each day. The problem I found is that after a job execution, when I execute again the same process (with different job parameters, of course) I see Spring batch generates a new Job instance BUT the variables values remain in memory for the new execution.

    How is it possible? New instances don't create new Java instances? Problem configuration?

    My JobLoader configuration:

    Code:
    <bean id="jobLoader" class="org.springframework.batch.core.configuration.support.AutomaticJobRegistrar">
        <property name="applicationContextFactories">
            <bean class="org.springframework.batch.core.configuration.support.ClasspathXmlApplicationContextsFactoryBean">
                <property name="resources" value="classpath*:/META-INF/spring/batch/jobs/*.xml" />
            </bean>
        </property>
        <property name="jobLoader">
            <bean class="org.springframework.batch.core.configuration.support.DefaultJobLoader">
                <property name="jobRegistry" ref="jobRegistry" />
            </bean>
        </property>
    </bean>

    Thanks,

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    What do you mean by "variables"? Of the top of my head, I would want to see your job configuration. By default, Spring beans are singletons so launching a new job instance using them would not create new instances of these classes and so the state would persist. If you can provide your job configuration, it would help.
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  3. #3
    Join Date
    Oct 2012
    Location
    Madrid
    Posts
    20

    Default

    Ok mminella, that is what I was thinking. I don't have right now the job configuration but I can tell you how I design my batch processes: ItemReader, ItemProcessor and ItemWriter are beans, and the problem I realize is that, after a execution, all the values (List, String, etc...) persist in memory. Of course, in the @AfterStep I control this problem, by initializing all the values.

    What do you think about this?

  4. #4
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    What about declaring them as prototypes instead of singletons?
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

  5. #5
    Join Date
    Oct 2012
    Location
    Madrid
    Posts
    20

    Default

    Well, maybe. I test it for one process tomorrow, but I would like to know the best way to design a Spring Batch process.

    Thanks,

Tags for this Thread

Posting Permissions

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