Announcement Announcement Module
Collapse
No announcement yet.
Variables values remain in memory after Spring Batch Job execution Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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?

      Comment


      • #4
        What about declaring them as prototypes instead of singletons?

        Comment


        • #5
          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,

          Comment

          Working...
          X