Announcement Announcement Module
Collapse
No announcement yet.
Problem starting the batch job 2nd. time Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem starting the batch job 2nd. time

    I am experiencing a problem when the batch job is called the 2nd. time. The batch job is to be run once a day (primarily).

    I have an applications with an jmx interface. I call the JobStarterImpl, - run method with the name of the job as the parameter.
    The first run, - works fine. But the 2nd. run failes with the enclosed exception. Which was no problem with the m3 version, - from which I have just upgraded from.

    Code:
    Exception in thread "Thread-8" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subscriptionDeactivateDaysRuleJob' defined in class path resource [batch/jobs/subscriptionDeactivateDaysRuleJob.xml]: Initialization of bean failed; nested exception is org.springframework.beans.FatalBeanException: Cannot register job configuration; nested exception is org.springframework.batch.core.repository.DuplicateJobException: A job configuration with this name [subscriptionDeactivateDaysRuleJob] was already registered
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:404)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:375)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:263)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:170)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:260)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:184)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:163)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:430)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:105)
    	at no.aftenposten.accountbalancer.spring.ClassPathXmlApplicationContextJobFactory.createJob(ClassPathXmlApplicationContextJobFactory.java:53)
    	at no.aftenposten.accountbalancer.spring.JobStarterImpl$1.run(JobStarterImpl.java:43)
    	at java.lang.Thread.run(Thread.java:613)
    Caused by: org.springframework.beans.FatalBeanException: Cannot register job configuration; nested exception is org.springframework.batch.core.repository.DuplicateJobException: A job configuration with this name [subscriptionDeactivateDaysRuleJob] was already registered
    	at org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor.postProcessAfterInitialization(JobRegistryBeanPostProcessor.java:97)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:357)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:463)
    	... 16 more
    Caused by: org.springframework.batch.core.repository.DuplicateJobException: A job configuration with this name [subscriptionDeactivateDaysRuleJob] was already registered
    	at org.springframework.batch.core.configuration.support.MapJobRegistry.register(MapJobRegistry.java:53)
    	at org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor.postProcessAfterInitialization(JobRegistryBeanPostProcessor.java:93)
    	... 19 more
    This is the implementation called via Jmx.

    Code:
    package no.aftenposten.accountbalancer.spring;
    
    import org.springframework.batch.core.launch.JobLauncher;
    import org.springframework.batch.core.configuration.JobLocator;
    import org.springframework.batch.core.configuration.JobFactory;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    import no.aftenposten.accountbalancer.scheduler.AbBatchInvoker;
    
    /**
     * Launch each job into a new separate context.
     * <p/>
     * Date: Jan 25, 2008
     * Time: 4:22:18 PM
     *
     * @author regearne (created by)
     * @author $Author: regearne $
     * @version $Revision: 14027 $ $Date: 2008-04-11 13:56:52 +0200 (Fri, 11 Apr 2008) $
     */
    public class JobStarterImpl extends StartServer implements AbBatchInvoker {
        private static transient Log log = LogFactory.getLog(JobStarterImpl.class);
    
        JobLauncher jobLauncher;
        JobLocator jobLocator;
    
        public void setJobLocator(JobLocator jobLocator) {
            this.jobLocator = jobLocator;
        }
    
        public void setJobLauncher(JobLauncher jobLauncher) {
            this.jobLauncher = jobLauncher;
        }
    
        public void run(final String jobName) {
    
            new Thread(new Runnable() {
    
                public void run() {
                    log.info("Loading job xml: " + jobName);
                    JobFactory jobFactory = new ClassPathXmlApplicationContextJobFactory(
                            jobName, "batch/jobs/" + jobName + ".xml", parent);
                    jobFactory.createJob();
                }
    
                ;
            }).start();
    
        }
    
        public void stop(String s) {
        }
    
    }
    Last edited by geira; Apr 14th, 2008, 12:56 AM.
Working...
X