Announcement Announcement Module
Collapse
No announcement yet.
Quartz Scheduler problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Quartz Scheduler problem

    I am facing some problem while running multiple notification tasks.

    Here is the brief about the problem :

    I am having two XML files for notification one will call notification1 and another will call the notification2,notification1 is invoked after 20 sec and notification2 is invoked after every 10 sec, at every 10 sec interval the notification2 is invoked properly but during the 20 sec interval it is invoked twice and notification1 is not invoked.

    Is there anything wrong I am doing in my XML ?

    Note: 1. Can anyone give idea about the Bean Overriding.
    2. I am writting both the XML file in the SpringContext
    3. Both the Notification1 and Notification2 extends same abstract class


    XML1


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
    <beans default-autowire="byName">
    <bean id="quartzScheduler"
    class="org.springframework.scheduling.quartz.Sched ulerFactoryBean" lazy-init="default" autowire="default" dependency-check="default">
    <property name="schedulerName">
    <value>notification1.quartzScheduler</value>
    </property>
    <property name="triggers">
    <list />
    </property>
    </bean>

    <bean id="job1" init-method="start"
    class="demo.Notification1" lazy-init="default" autowire="default" dependency-check="default">

    <property name="cronExpression">
    <!-- run the refresh every ten sec -->
    <value>0/10 * * * * ?</value>
    </property>
    <property name="jobDetail">
    <bean
    class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
    <property name="targetObject"
    ref="job1" />
    <property name="targetMethod" value="executeOnSchedule" />
    <property name="concurrent" value="false" />
    </bean>
    </property>
    </bean>
    </beans>





    XML2


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
    <beans default-autowire="byName">
    <bean id="quartzScheduler"
    class="org.springframework.scheduling.quartz.Sched ulerFactoryBean" lazy-init="default" autowire="default" dependency-check="default">
    <property name="schedulerName">
    <value>notification2.quartzScheduler</value>
    </property>
    <property name="triggers">
    <list />
    </property>
    </bean>

    <bean id="job2" init-method="start"
    class="demo.Notification2" lazy-init="default" autowire="default" dependency-check="default">

    <property name="cronExpression">
    <!-- run the refresh every twenty sec -->
    <value>0/20 * * * * ?</value>
    </property>
    <property name="jobDetail">
    <bean
    class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
    <property name="targetObject"
    ref="job1" />
    <property name="targetMethod" value="executeOnSchedule" />
    <property name="concurrent" value="false" />
    </bean>
    </property>
    </bean>
    </beans>



    Thanks for your valuable time.

    Regards,
    Ranjan

  • #2
    hi,
    I'm bigenner in quartz scheduler and i hope to some one helps me for resolve my problem:

    I would schedule a job and ability to recover if the job failed.
    so I read some pdf and he advice to introduce a joblistener but I do not know how to use it.

    In the First , I do this line in the xml file of the scheduler:
    Code:
    	<!-- *************************************************************** -->
    	<!-- Declare a job listener that will take care of job retries, etc. -->
    	<!-- *************************************************************** -->
    
    <bean id="myJobListener" class="org.quartz.JobListener">
            <property name="name" value="myJobListener"/>
            <property name="jobDetail" ref="myJobListener"></property>
        </bean>
    Then I create the joblistener class which is as follows:

    Code:
    package com.scheduler.listener;
    
    import org.quartz.JobDetail;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    import org.quartz.JobListener;
    import org.springframework.batch.core.JobExecution;
    
    public class UnJobListener implements JobListener {
    	public static final String LISTENER_NAME = "dummyJobListenerName";
    
    	public UnJobListener() {
    		// TODO Auto-generated constructor stub
    	}
    
    	@Override
    	public String getName() {
    		// TODO Auto-generated method stub
    		return LISTENER_NAME;
    	}
    
    	@Override
    	// Run this if job is about to be executed.
    	public void jobToBeExecuted(JobExecutionContext context) {
    		// TODO Auto-generated method stub
    		String jobName = context.getJobDetail().getKey().toString();
    		System.out.println("jobToBeExecuted");
    		System.out.println("Job : " + jobName + " is going to start...");
    		 //JobDetail jobDetail = context.getJobDetail();
    //         MyJobDetail myJobDetail = (MyJobDetail) jobDetail;          
    //         jobDetail.getJobDataMap().put("MessageAdded", myJobDetail.getMyMessage());
    		
    		
    		
    	}
    
    	
    	@Override
    	public void jobExecutionVetoed(JobExecutionContext context) {
    		// TODO Auto-generated method stub
           System.out.println("jobExecutionVetoed");
    	}
    
    	@Override
    	public void jobWasExecuted(JobExecutionContext context,
    			JobExecutionException jobException) {
    		// TODO Auto-generated method stub
    		System.out.println("jobWasExecuted");
    		 
    		String jobName = context.getJobDetail().getKey().toString();
    		System.out.println("Job : " + jobName + " is finished...");
     
    		if (!jobException.getMessage().equals("")) {
    			System.out.println("Exception thrown by: " + jobName
    				+ " Exception: " + jobException.getMessage());
    		}
    	}
    
    }
    This shows me that errors are:

    INFO: Closing JPA EntityManagerFactory for persistence unit 'NCAKernel'
    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'myJobListener' defined in class path resource [schedulerAppContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.quartz.JobListener]: Specified class is an interface
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:997)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBeanInstance(Abst ractAutowireCapableBeanFactory.java:943)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:485)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
    at com.prosodie.nca.scheduler.StandaloneScheduler.mai n(StandaloneScheduler.java:46)
    Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.quartz.JobListener]: Specified class is an interface
    at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:56)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.instantiateBean(Abstrac tAutowireCapableBeanFactory.java:990)
    ... 13 more


    could someone help me please, i need it for this day.

    Thanks a lot

    Comment


    • #3
      Hi!
      This forum for Spring Integration Framework.
      So, for a start try to figure out "Why you should ask help here or there?".
      Regarding:
      Could not instantiate bean class [org.quartz.JobListener]: Specified class is an interface
      org.quartz.JobListener is really an interface. It's problem of your configuration: you declare Spring Bean not by class, but by interface.
      Please, study more about Spring: http://static.springsource.org/sprin...eduling-quartz

      Take care,
      Artem

      Comment


      • #4
        Originally posted by Cleric View Post
        Hi!
        This forum for Spring Integration Framework.
        So, for a start try to figure out "Why you should ask help here or there?".
        Regarding:

        org.quartz.JobListener is really an interface. It's problem of your configuration: you declare Spring Bean not by class, but by interface.
        Please, study more about Spring: http://static.springsource.org/sprin...eduling-quartz

        Take care,
        Artem
        Int the first thanks for your reply,

        I'm here because i need some one to help me or to give me an idea.
        for the class i modified this but i have always a problème :

        <bean id="myJobListener" class="com.prosodie.nca.scheduler.myJobListener">
        <property name="name" value="myJobListener"/>
        <property name="jobDetail" ref="myJobListener"></property>
        </bean>
        Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'accesIhmDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [com.prosodie.nca.scheduler.myJobListener] for bean with name 'myJobListener' defined in class path resource [schedulerAppContext.xml]; nested exception is java.lang.ClassNotFoundException: com.prosodie.nca.scheduler.myJobListener
        at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.postProcessPropertyValues (PersistenceAnnotationBeanPostProcessor.java:342)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1106)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
        at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
        at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
        at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:585)
        at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
        at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
        at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
        at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
        at com.prosodie.nca.scheduler.StandaloneScheduler.mai n(StandaloneScheduler.java:46)
        Caused by: org.springframework.beans.factory.CannotLoadBeanCl assException: Cannot find class [com.prosodie.nca.scheduler.myJobListener] for bean with name 'myJobListener' defined in class path resource [schedulerAppContext.xml]; nested exception is java.lang.ClassNotFoundException: com.prosodie.nca.scheduler.myJobListener
        at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1262)
        at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.predictBeanType(Abstrac tAutowireCapableBeanFactory.java:576)
        at org.springframework.beans.factory.support.Abstract BeanFactory.isFactoryBean(AbstractBeanFactory.java :1331)
        at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanNamesForType(DefaultList ableBeanFactory.java:317)
        at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanNamesForType(DefaultList ableBeanFactory.java:298)
        at org.springframework.beans.factory.BeanFactoryUtils .beanNamesForTypeIncludingAncestors(BeanFactoryUti ls.java:142)
        at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findDefaultEntityManagerF actory(PersistenceAnnotationBeanPostProcessor.java :527)
        at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.findEntityManagerFactory( PersistenceAnnotationBeanPostProcessor.java:496)
        at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.resolv eEntityManager(PersistenceAnnotationBeanPostProces sor.java:657)
        at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor$PersistenceElement.getRes ourceToInject(PersistenceAnnotationBeanPostProcess or.java:630)
        at org.springframework.beans.factory.annotation.Injec tionMetadata$InjectedElement.inject(InjectionMetad ata.java:150)
        at org.springframework.beans.factory.annotation.Injec tionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor.postProcessPropertyValues (PersistenceAnnotationBeanPostProcessor.java:339)
        ... 13 more
        Caused by: java.lang.ClassNotFoundException: com.prosodie.nca.scheduler.myJobListener
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.util.ClassUtils.forName(ClassU tils.java:258)
        at org.springframework.beans.factory.support.Abstract BeanDefinition.resolveBeanClass(AbstractBeanDefini tion.java:417)
        at org.springframework.beans.factory.support.Abstract BeanFactory.doResolveBeanClass(AbstractBeanFactory .java:1283)
        at org.springframework.beans.factory.support.Abstract BeanFactory.resolveBeanClass(AbstractBeanFactory.j ava:1254)
        ... 25 more

        Comment


        • #5
          1. You have wrong bean definition: you try to inject bean myJobListener to the bean myJobListener, into itself.
          2.
          Caused by: java.lang.ClassNotFoundException: com.prosodie.nca.scheduler.myJobListener
          Does it say anything for you?

          Sorry, you don't do anything by yourself and you want that we do it for you, but the money for work will be got by you
          http://lmgtfy.com/?q=spring+quartz+example

          Comment

          Working...
          X