Results 1 to 5 of 5

Thread: scheduling problem using quartz

  1. #1

    Question scheduling problem using quartz

    Hi,

    I am using Spring 1.2. I tried a simple job scheduling by reading
    http://static.springframework.org/sp...cheduling.html

    Basically, I have written a simple class that extends QuartzJobBean.

    Code:
    package example;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.quartz.JobExecutionContext;
    import org.quartz.JobExecutionException;
    import org.springframework.scheduling.quartz.QuartzJobBean;
    
    /**
     * @author Vaibhav Mishra
     */
    public class QuartzSample extends QuartzJobBean {
    
        /**
         * logger for this class
         */
        private Log log = LogFactory.getLog(QuartzSample.class);
    
        /*
         * (non-Javadoc)
         * 
         * @see org.springframework.scheduling.quartz.QuartzJobBean
         *      #executeInternal(org.quartz.JobExecutionContext)
         */
        @Override
        protected void executeInternal(JobExecutionContext arg0)
                throws JobExecutionException {
            log.error("Sample job executed using Quartz.");
        }
    }
    And I have specified the spring beans as -

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean name="sampleJob"
    		class="org.springframework.scheduling.quartz.JobDetailBean">
    		<property name="jobClass" value="example.QuartzSample" />
    	</bean>
    
    	<bean id="cronTrigger"
    		class="org.springframework.scheduling.quartz.CronTriggerBean">
    		<property name="jobDetail" ref="sampleJob" />
    		<!-- s m h d M [y] current setting 6:20 pm -->
    		<property name="cronExpression" value="0 20 18 * * ?" />
    	</bean>
    
    	<bean id="schedulerFactory"
    		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    		<property name="autoStartup" value="true" />
    		<property name="triggers">
    			<list>
    				<ref bean="cronTrigger" />
    			</list>
    		</property>
    	</bean>
    </beans>
    I have my application deployed in JBoss 4.0.2.
    JBoss restarts without any exception, but the things does not seems to be working. I even get the following line printed on JBoss console -

    Code:
    11:56:26,187 INFO  [QuartzScheduler] Scheduler QuartzScheduler_$_NON_CLUSTERED started.
    But, job does not run at scheduled time.
    Please help.

    Regards,
    Vaibhav

  2. #2

    Exclamation TimerTask is working fine

    I tried the same thing using TimerTask and it is working fine.

    Code:
    package example;
    
    import java.util.TimerTask;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    /**
     * @author Vaibhav Mishra
     */
    public class TimerTaskSample extends TimerTask {
    
        /**
         * logger for this class
         */
        private Log log = LogFactory.getLog(TimerTaskSample.class);
    
        /*
         * (non-Javadoc)
         * 
         * @see java.util.TimerTask#run()
         */
        @Override
        public void run() {
            log.error("Sample job executed using TimerTask.");
        }
    }
    And

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
        "http://www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    	<bean id="sampleTimerJob" class="com.alacre.f1.TimerTaskSample">
    	</bean>
    
    	<bean id="scheduledTask"
    		class="org.springframework.scheduling.timer.ScheduledTimerTask">
    		<property name="delay" value="10000" />
    		<property name="period" value="50000" />
    		<property name="timerTask" ref="sampleTimerJob" />
    	</bean>
    
    	<bean id="timerFactory"
    		class="org.springframework.scheduling.timer.TimerFactoryBean">
    		<property name="scheduledTimerTasks">
    			<list>
    				<ref bean="scheduledTask" />
    			</list>
    		</property>
    	</bean>
    
    </beans>

  3. #3
    Join Date
    Mar 2006
    Posts
    28

    Default

    add this in <ref bean="simpleTrigger"/>
    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
    <!-- see the example of method invoking job above -->
    <property name="jobDetail" ref="exampleJob"/>
    <!-- 10 seconds -->
    <property name="startDelay" value="10000"/>
    <!-- repeat every 50 seconds -->
    <property name="repeatInterval" value="50000"/>
    </bean>

    in configuartion file

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney
    Posts
    503

    Default

    What if you change the cron expression to something a bit more frequent for testing purposes

    e.g.

    0/20 * * * * ?

    How are you determining that the job isn't running? Are you sure that the log4j.xml config file in the conf directory is setup to show your log messages?

  5. #5

    Talking Scheduler doesnt seem to know about your Job.

    I don't see when you are telling the scheduler about this job.


    this is how i do it..

    Code:
    public class MyServiceImpl
          implements MyService,
           ApplicationContextAware{
    
        Scheduler scheduler = null;
        ApplicationContext context = null;
    
        private void initJob()
        {
            long   startTime = System.currentTimeMillis(  ); 
    
            CronTrigger trigger = ( JobDetail ) context.getBean( "myCronTrigger" );
    
            try {
                JobDetail job = ( JobDetail ) context.getBean( "myJob" );
                job.setGroup( "Group" );
                job.setName(“myJob”);//dont think u need this..bean id is name..?
                scheduler.scheduleJob( job, trigger );
            }
            catch ( SchedulerException e ){
                logger.error( e );
            }
        }
    }
    /^\\ Pharaoh /^\\
    http://pharaohofkush.blogspot.com/

    Jeryl Cook

Posting Permissions

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