Results 1 to 3 of 3

Thread: Spring scheduled job getting called twice

  1. #1
    Join Date
    Jul 2006
    Posts
    126

    Default Spring scheduled job getting called twice

    Hi,

    I am trying to use spring (v 3.0.1.RELEASE-A) based scheduler for a scheduler application. I just started using it with a cron expression. However I find that only sometimes the job is called twice.

    My spring configuration is
    Code:
    	<task:scheduled-tasks scheduler="jobScheduler">
    	    <task:scheduled ref="jobProcessor" method="process" cron="0 0/1 * * * *"/>
    	</task:scheduled-tasks>
    	<task:scheduler id="jobScheduler" pool-size="1"/>
        <bean id="jobProcessor" class="MyScheduledJobProcessor"/>
    To see how the job is getting called I have put few debug sysouts, the MyScheduledJobProcessor class looks like

    Code:
    public class MyScheduledJobProcessor implements JobProcessor{
    
    	public void process() {
    		System.out.println("ScheduledJobProcessor called at " + new Date() + " and "+ Thread.currentThread().getId());
    	}
    }
    The output looks like
    ScheduledJobProcessor called at Fri Dec 09 03:59:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 03:59:59 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:00:00 EST 2011 and 7 // Called twice here
    ScheduledJobProcessor called at Fri Dec 09 04:01:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:02:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:03:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:03:59 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:04:00 EST 2011 and 7 // Called twice here
    ScheduledJobProcessor called at Fri Dec 09 04:05:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:06:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:06:59 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:07:00 EST 2011 and 7 // Called twice here
    ScheduledJobProcessor called at Fri Dec 09 04:08:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:09:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:10:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:11:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:11:59 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:12:00 EST 2011 and 7 // Called twice here
    ScheduledJobProcessor called at Fri Dec 09 04:13:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:14:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:15:00 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:15:59 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:17:00 EST 2011 and 7 // Called twice here
    ScheduledJobProcessor called at Fri Dec 09 04:17:59 EST 2011 and 7
    ScheduledJobProcessor called at Fri Dec 09 04:18:00 EST 2011 and 7

    I am not able to figure out what I did wrong. It's a simple cron job which is supposed to run every minute. Moreover there is no pattern in calling the job twice.

    Any help is appreciated!

    Shashi
    Last edited by shashi; Dec 11th, 2011 at 11:07 PM.

  2. #2
    Join Date
    Jul 2006
    Posts
    126

    Default

    Hi,

    It's strange but didn't get any replies for my post. Could somebody please throw some light on the issue I am facing. Probably an issue with my configuration or a bug?

    Regards,
    Shashi

  3. #3
    Join Date
    Aug 2005
    Location
    Bologna, Italy
    Posts
    79

    Default

    Maybe in the web.xml you've declared two contexts?

Posting Permissions

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