History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: QUARTZ-65
Type: Bug Bug
Status: Closed Closed
Resolution: Not A Problem
Priority: Major Major
Assignee: James House
Reporter: Daniel Fernández
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Quartz Scheduler

CronTrigger with startDate in the past executes once before correctly using schedule

Created: 08/Sep/04 06:39 AM   Updated: 03/Dec/04 02:50 PM
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: 1.4.3

File Attachments: 1. Java Source File App.java (4 kb)
2. Java Source File MyJob.java (0.3 kb)
3. File quartz-config.properties (0.1 kb)

Environment: Sun J2SE 1.4.2_04. Quartz versions 1.3.4 and 1.4.2. OS: Fedora Core 2 on i386.


 Description  « Hide
When I create a CronTrigger and setting a start date to it (via trigger.startDate) which is in the past, and then adding a cron expression (via trigger.setCronExpression) like the following:

0 0 * * * ? *

...which means "execute every hour, every day", what I get is an execution "in the past" and then the real scheduling, waiting for the next hour (0 minutes) starting in the moment of execution.

I'll explain it with an example. I made a small simulator which executes a task which simply writes an asterisk ("*") on the standard output. The task gets scheduled and then the program enters an infinite while loop in which it asks for the next execution time every three seconds).
Here you can see this effect:

------------------
Date: 08 sep 2004 13:07:46
Trigger start date: 08 sep 2004 09:30:00
Trigger end date: 10 sep 2004 21:00:00
Trigger expression: 0 0 * * * ? *
Getting scheduler instance
Starting scheduler
Adding job to scheduler
Scheduling triggger
Entering loop...
(08 sep 2004 13:07:46) NEXT FIRE TIME: Wed Sep 08 10:00:00 CEST 2004
*
(08 sep 2004 13:07:49) NEXT FIRE TIME: Wed Sep 08 14:00:00 CEST 2004
(08 sep 2004 13:07:52) NEXT FIRE TIME: Wed Sep 08 14:00:00 CEST 2004
(08 sep 2004 13:07:55) NEXT FIRE TIME: Wed Sep 08 14:00:00 CEST 2004
(08 sep 2004 13:07:58) NEXT FIRE TIME: Wed Sep 08 14:00:00 CEST 2004
(08 sep 2004 13:08:01) NEXT FIRE TIME: Wed Sep 08 14:00:00 CEST 2004
...
------------------

As you can see, the first execution gets planned "out" of the scheduling, as the first execution should occur at "14:00".

This *does not happen* if the start date of the trigger is not in the past. In that case it works perfectly.

Thanks.


 All   Comments   Change History      Sort Order:
Daniel Fernández - [08/Sep/04 06:41 AM ]
Testing app code (Main class)

Daniel Fernández - [08/Sep/04 06:41 AM ]
Testing app code (task class)

Daniel Fernández - [08/Sep/04 06:43 AM ]
Testing app code (properties file for fail)

James House - [03/Dec/04 02:50 PM ]

This is expected behavior. You are causing a misfire to occur.

There is one set of users who want the current behavior (fire once for missed events since the start date, or do whatever the misfire instruction says), and another set of users who want the behavior you specify.

Leaving it the way it is best allows for both factions - you can fix your problem by using the current time for the start date, or even leaving the start date empty.